Ping Watchdog Script

From Deliberant wiki

Jump to: navigation, search

It is possible to create PING Watchdog functionality using a custom script with LigoWave devices. There are two scripts required, one is the actual ping watchdog script and one is a startup script that runs the ping watchdog script at boot.

Image:!.png This is an advanced tutorial. Modifying system level files may render the device unusable if not done correctly!

To implement these two scripts one will need to SSH into the device and use the vi utility to create these two files in the /etc/persistent directory. Once in place, the ping watchdog should be functional.

You will want to replace the line below that says # INSERT COMMAND HERE with a command such as reboot now

/etc/persistent/ping_watchdog

#!/bin/sh
# HOST to Ping
HOST="10.3.0.3"
# number of ping requests
COUNT=9
# number of failed to allow
FAIL=5
echo "Ping Watchdog Started" >> /var/log/messages
while true
do
 echo "Sleeping for 1 minute"
 sleep 60
   count=$(ping -c $COUNT $HOST | grep 'received' | sed -e 's/^9 packets transmitted, //' | sed 's/ received.*$//')
     if [ $count -le $(($COUNT - $FAIL)) ]; then
             echo $count
                 echo "WATCHDOG ::: Host : $HOST is down (ping failed) at $(date)" >> /var/log/messages
                 # INSERT COMMAND HERE
                       else
                             echo "Ping Successful "
                               fi
     echo " $count of $COUNT "
                               done

/etc/persistent/rc.local

#!/bin/sh
sh /etc/persistent/ping_watchdog &


  • NOTE When changing the COUNT number, the ping line must be updated with s/^$COUNT
Personal tools