Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get individual values from the output of systemctl status

[root@localhost etc]# systemctl status blu_av
● blu_av.service - avscan
   Loaded: loaded (/etc/systemd/system/blu_av.service; disabled; vendor preset: disabled)
   Active: active (running) since Fri 2018-03-16 16:31:14 IST; 3s ago
 Main PID: 31934 (av)
   CGroup: /system.slice/blu_av.service
           ├─31934 /opt/services/av
           └─31956 /opt/services/av

Mar 16 16:31:14 localhost.localdomain systemd[1]: Started avscan.
Mar 16 16:31:14 localhost.localdomain systemd[1]: Starting avscan...

If the above is the output of my status. I want to retrieve the service name, uptime and status by using a python script.

like image 615
user9279273 Avatar asked Dec 01 '22 14:12

user9279273


1 Answers

systemd services have a whole list of properties. To get the start time for example; you could run:

systemctl show your.service --property=ActiveEnterTimestamp

which would give something like:

ActiveEnterTimestamp=Fri 2019-05-03 09:35:02 CEST

To see the list of all properties; just run

systemctl show your.service
like image 192
Chris Maes Avatar answered Dec 03 '22 03:12

Chris Maes