I need a script to check the dialup internet connection if it is disconnected will run the pon, when get connected exit the script, but if connection fails will try 3 times to connect, finally after third fail of try sould shutdown the computer. this is the one i get but it is not working and i want to be simple pretty script:
#!/bin/bash
WTIME="60"
#here I defined the logfile's location
logfile=/home/user/pppd/con.log
#the heart of this script lies right here
#just ping google.com with one packet, pipe it's stderr to egrep and match either of those words
#egrep's -c tells to output the number of matches
status=$(ping -c 1 google.com 2>&1 | egrep -c "\<unknown\>|\<unreachable\>")
if [ $status -eq 0 ]; then
#the -n says stay in this line after outputting
#print an empty line
echo "" >> $logfile
echo -n "Already Connected - " >> $logfile
#output date to the logfile
date >> $logfile
#exit with success code
exit 0
fi
if [ ! $status -eq 0 ]; then
echo "" >>$logfile
echo -n "Not Connected - " >> $logfile
date >> $logfile
poff -a 2>&1 >> $logfile
pon 2>1 >> $logfile
sleep $WTIME
exit 1
else
exit 0
fi
if [ ! $status -eq 0 ]; then
echo "" >>$logfile
echo -n "Not Connected - " >> $logfile
date >> $logfile
poff -a 2>&1 >> $logfile
pon 2>1 >> $logfile
sleep $WTIME
exit 1
else
exit 0
fi
if [ ! $status -eq 0 ]; then
echo "" >>$logfile
echo -n "Not Connected - " >> $logfile
date >> $logfile
poff -a 2>&1 >> $logfile
pon 2>1 >> $logfile
sleep $WTIME
exit 1
else
exit 0
fi
if [ ! $status -eq 0 ]; then
echo "Connection failed shutting down pc- $(date +%Y-%m-%d-%H:%M:%S)" | mail -s "pon.sh"
[email protected] /sbin/shutdown -h now
fi
exit 0