One of my headless wireless devices have been freezing lately, and since it’s in a somewhat isolated location, I have no idea when it freezes.
So I wrote up a quick script to check to see whether it’s up and I’m running it every hour so that it alerts me when it goes down. It will also alert me once it comes back up, in case it comes back up by itself !
The script will also save the last state that the device was in so that it will only email me once when the device goes down.
if [[ -z $1 ]]; then
echo Usage: ./pingcheck.sh \
if [ ! -f /tmp/$1.status ]; then
reply=`ping -c 1 $ip | grep 64\ bytes | wc -l`
echo $reply > /tmp/$1.status
if [[ $oldstatus -ne $reply ]]; then
if [[ $reply -eq 1 ]]; then
echo $1 is online | mail -s "Node is online" $email
echo $1 is offline | mail -s "Node is offline" $email