Simple SSH services status monitoring
Fri, 16 Sep 2011 22:52:07 +0000
Current project I'm working on benefits from automated test suite run on few Linux-based devices. Tests are running 24x7, but sometimes device hangs (reason is still under investigation) and SSH access is blocked then.
In order to track the problem I redirected syslog (busybox-based, BTW) via network and added local automatic monitoring service that will show me when a part of my test installation go down.
The script is really simple and uses GNOME notification tool called notify-send.
#!/bin/sh if ! ping -q -c 1 google.com > /dev/null then # no network present exit fi for machine do F=/tmp/$machine F2=/tmp/$machine.previous if ssh $machine 'echo OK' >$F 2>&1 then rm -f $F $F2 else if test -f $F2 then notify-send "$machine is not present: `cat $F`" fi mv $F $F2 fi done
Details:
- I'm checking if network is available in general (google ping)
- List of SSH machines given on command line
- I assume SSH keys are setup - no password prompt
- Check state is held in /tmp/ directory
Script is started periodically from crontab:
* 9-17 * * 1-5 srv-monitor-ssh alfa beta delta zeus zeus2
and reports failure on second failed check.