You are not logged in.

#1 2012-11-23 00:02:51

tsr-nc
Member
Registered: 2009-02-07
Posts: 40

script to list all active systemd units

Is there a script to list all active systemd units for use in conky. ie an equivelent to "rc.d list -s"

Offline

#2 2012-11-23 00:35:56

mjheagle8
Member
From: /home/mjheagle8
Registered: 2009-07-12
Posts: 186

Re: script to list all active systemd units

does "systemctl list-units --full | grep active" do what you're looking for?


Desktop/Laptop - DWM :: VM - screen
Registered Linux User Number 483137 :: Victory! :: GitHub

Offline

#3 2012-11-23 00:43:36

ninian
Member
From: United Kingdom
Registered: 2008-02-24
Posts: 726
Website

Re: script to list all active systemd units

I was thinking about the following if you're just wanting services:

systemctl list-units -t service --no-pager --no-legend | grep active

edit: While I'm here, here's a script I wrote which allows you to manipulate services using a function and dmenu. The final output is piped in monospace font to gxmessage, but of course you can hack this around in lots of ways.

#!/bin/bash
#

services()
{
sm="dmenu -l 20 -fn Monospace-8 -p"
s1=$(systemctl list-unit-files -t service --no-legend | $sm Service); s1=${s1/%service*/service}; [[ -z $s1 ]] && exit
s2=$(echo -e "status\nstart\nstop\nrestart\nenable\ndisable" | $sm "Action"); [[ -z $s2 ]] && exit
if [[ $s2 == "status" ]]; then unset s3; else s3="gksudo --"; fi
eval $s3 systemctl --no-pager $s2 $s1 2>&1 | gxmessage -file - -title Services -center -fn "Monospace 8"
} 

services

wink

Last edited by ninian (2012-11-23 00:46:46)

Offline

#4 2012-11-23 18:37:48

tsr-nc
Member
Registered: 2009-02-07
Posts: 40

Re: script to list all active systemd units

Thank you kindly
I ended up using this if anyone else could use it here it is

systemctl list-units -t service --no-pager --no-legend | grep active | grep -v systemd | grep -v exited | awk '{ print $1 }'

Last edited by tsr-nc (2012-11-23 19:24:15)

Offline

Board footer

Powered by FluxBB