5

like using systemctl is-active <servicename> gives is if service is active or failed then is it possible to get the uptime or downtime of the systemd service all using systemctl ?

time systemctl status kdm|cat
* kdm.service - LSB: X display manager for KDE
   Loaded: loaded (/etc/init.d/kdm; generated; vendor preset: enabled)
   Active: active (exited) since Wed 2017-06-21 12:03:26 CEST; 1h 42min ago
     Docs: man:systemd-sysv-generator(8)
    Tasks: 0 (limit: 4915)
   CGroup: /system.slice/kdm.service

is it possible to get the 1h 42min using systemctl

Ciasto piekarz
  • 7,853
  • 18
  • 101
  • 197

2 Answers2

8

Using GNU grep with options -P and -o

systemctl status kdm | grep -Po ".*; \K(.*)(?= ago)"
Philippe
  • 20,025
  • 2
  • 23
  • 32
5

Using systemctl's property WatchdogTimestamp

 blr8-100-208-Vin:~ # systemctl show novell-nss --property WatchdogTimestamp
 WatchdogTimestamp=Tue 2020-11-24 17:30:20 IST
Vinay Kumar D
  • 86
  • 1
  • 2
  • 4
  • What's the source material that describes WatchdogTimestamp as the "uptime" of the service? – Eric May 12 '22 at 01:17