Mini Ping Watchdog
Posted: Mon Jan 16, 2017 11:58 am
Hi,
I've just been looking for something to regularly 'ping' from my TP-Link WR841N v11 to try and keep my TP-Link AV500 PowerLines from going sleep at night, losing connection, and not waking up again.
Ping Watchdog sounded great, but seems my TP-Link doesn't have enough space to install it I'm a bit surprised a little ping module comes to 11MB?
Anyway, for a bit of fun I created a quick 'mini' Ping Watchdog script and log the results. In case its of use to anyone, I thought to copy it here, might save someone a few minutes The slightly strange logfile truncation is just to keep tail -f working most of the time.
Log output just looks like
If anyone has any suggestions on where to look at Ping Watchdog, I may see if I can make it suitable for smaller devices.
Cheers,
Alex
Install with crontab -e
Edit /root/ping.sh
I've just been looking for something to regularly 'ping' from my TP-Link WR841N v11 to try and keep my TP-Link AV500 PowerLines from going sleep at night, losing connection, and not waking up again.
Ping Watchdog sounded great, but seems my TP-Link doesn't have enough space to install it I'm a bit surprised a little ping module comes to 11MB?
Anyway, for a bit of fun I created a quick 'mini' Ping Watchdog script and log the results. In case its of use to anyone, I thought to copy it here, might save someone a few minutes The slightly strange logfile truncation is just to keep tail -f working most of the time.
Log output just looks like
Code: Select all
root@TP-LINK:~# tail -f /var/log/192.168.0.1.pings
2017-01-16 15:46:00 OK 12.995
2017-01-16 15:47:00 OK 13.718
2017-01-16 15:48:01 OK 9.242
2017-01-16 15:49:01 OK 9.842
2017-01-16 15:50:01 OK 3.914
Cheers,
Alex
Install with crontab -e
Code: Select all
* * * * * /root/ping.sh
Code: Select all
#!/bin/sh
IP=192.168.0.1 # address to ping
LOGFILE=/var/log/$IP.pings
LOGLENMAX=10000 # Maximim number of lines in logfile
LOGLENTRIM=9000 # Size to trim logfile back down to when max length reached
/bin/ping -W 1 -c 1 $IP | awk '
BEGIN {
FS = "[ \t/]+"; logdate = strftime("%Y-%m-%d %H:%M:%S");
}
/packets/ {
if ($4==1) { result = "OK" } else { result = "FAIL" }
}
/round-trip/ { roundtrip=$6 }
END { print logdate " " result " " roundtrip }
' >> $LOGFILE
LOGLEN=`wc -l $LOGFILE | cut -d ' ' -f 1`
if [ $LOGLEN -gt $LOGLENMAX ]
then
tail -$LOGLENTRIM $LOGFILE >> $LOGFILE.new
mv $LOGFILE.new $LOGFILE
fi