|Ok, here it is:|
# Filename: checkip
# Purpose: continuously tests a network connection as per crontab settings
# crontab is set as follows:
# 0-59/1 6-18 * * 1-5 $HOME/bin/checkip
# Script tests every 1 minute, from 6 am to 6 pm, Monday through Friday
# As per example cronjob above
#set IP below - replace x's with actual IP address
# Test if IP responds to ping. Be patient; knock three times.
if ping -q -c 1 -w 2 $IP > /dev/null \
|| ( sleep 3 ; ping -q -c 1 -w 2 $IP > /dev/null ) \
|| ( sleep 3 ; ping -q -c 1 -w 2 $IP > /dev/null ) ; then
echo "Test for - $D - replied properly" >> $HOME/logs/checkip_log
# If the ip doesn't respond notify me
for STAFF in email@example.com ; do
echo "$IP is not responding" | mail -s "IP is not responding" $STAFF
# send date/time info to logfile with results of ping test
echo "Test for - $D - DID NOT reply properly" >> $HOME/logs/checkip_log
You'll have to put in the appropriate IP address and in the following line of code:
for STAFF in firstname.lastname@example.org do
change "email@example.com" to your actual email address.
Also, it will write a logfile. If you want it to go elsewhere, change the path.
You can adjust the cronjob to suit the time period you want the script running. In the cronjob example above is the path I have the script in. You can of course set that to wherever you want the script to run.
Don't forget to change that to an executable script and have it in a pathed directory.
I'd love to claim authorship of this little elegant script but alas, I suck totally at programming. This was created by a friend and coworker who's been working with UNIX for around 25 years.
I've adapted, and reused the core of this script (the "knock 3 times" ping) for multiple different scripts that all basically perform the same function. Which is to say, test that some network capable device (ie: printer, WAP, server, etc) is still connected and working.. If your cell provider supports it, you can even set it to send a text message alert to your cell phone by adding one line below the line that sends the email.
It matters not how straight the gate,
How charged with punishments the scroll,
I am the master of my fate;
I am the captain of my soul.