#!/bin/bash ################################################################################ ## Pinger v1.00 by Timo Taskinen (timo.taskinen@iki.fi) ## ## Creative Commons Attribution-Noncommercial-Share Alike 1.0 Finland License ## ## http://creativecommons.org/licenses/by-nc-sa/1.0 ## ################################################################################ # Target host or IP to ping. TARGET="example.com" # How many seconds to wait for a ping reply. # Default is 1, but increase it if your connection is laggy. TIMEOUT=1 # How many pings to send per every cycle. Default is 5. COUNT=5 # Log file. LOGFILE="/home/user/internet.log" # PID file. Set to /dev/null if you don't want one. PIDFILE="/home/user/pinger.pid" # Connection lost message. MSGLOST="Connection lost: " # Connection working message. MSGWORKING="Connection working: " # What to execute to get the timestamp string. TIMESTAMPSTRING="date" ######################################### ## After this there will be dragons. ## ######################################### broken=0 echo $$ > $PIDFILE while [ 1 ] do while [ "$broken" == 0 ] do ping -c $COUNT -W $TIMEOUT -A $TARGET > /dev/null if [ $? != 0 ] then # Oh noez, mah connecshun iz invisable! broken=1 fi sleep 1 done echo -n "$MSGLOST" >> $LOGFILE $TIMESTAMPSTRING >> $LOGFILE while [ "$broken" == 1 ] do ping -c $COUNT -W $TIMEOUT -A $TARGET > /dev/null if [ $? == 0 ] then # We has connecshun! Kthxbai. broken=0 fi sleep 1 done echo -n "$MSGWORKING" >> $LOGFILE $TIMESTAMPSTRING >> $LOGFILE echo >> $LOGFILE done echo > $PIDFILE