4

I'd like to check the status of a service in real-time.

I already know the command to check for example my Homebridge server:

/etc/init.d/homebridge status

When I'm debugging, I'd like to see the change of the status (for example running -> stopped) immediately.

Is there a command to keep track of this status in real-time, so I don't need to type in the command continuously?

6

You can use the watch utility to continuously update the status without using a loop.

watch --interval 1 'date; /etc/init.d/homebridge status'

which will update every second (the default is two seconds).

  • Thanks! This is exactly what I've looked for - a very clean solution! – user3191334 Sep 19 '17 at 21:58
2

You can get a continuous listing of a file with tail -f. I'm not familiar with your specific service, but according what I see online, it keeps two logs at /var/log/homebridge.log and /var/log/homebridge.err. You would then get the non-error log with this complete command:

tail -f /var/log/homebridge.log

(or add sudo before the whole line if necessary given your permissions).

  • Thanks for responding Brick but I really would like to find a way getting exactly this service status in real-time, in order to do some stuff responding to this status. I already worked with the two log files and tail -f but it isn't what I need for this situation. – user3191334 Sep 19 '17 at 20:31
1

Systemd tracks the processes attached to most persistent services, although I am not sure how well with regard to those controlled by old school SysV scripts, as homebridge appears to be.

In any case, a simple shell script like this will report that tracking information, including the point at which a process dies/exits for whatever reason.

#!/bin/sh

while true; do
    clear
    date
    systemctl status $1
    sleep 3
done 

Call that monitor.sh and run it monitor.sh homebridge. The time reported by date will change every three seconds if nothing else does. Note this will occupy a terminal until you stop it with Ctrl-C.

  • Thanks! I just changed the script a bit and just used /etc/init.d/$1 status and it works like a charm. For following readers, don't forget to sudo chmod +x monitor.sh before running it with ./monitor.sh homebridge:-) – user3191334 Sep 19 '17 at 21:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.