cron scripting and ping
Long time listener, first time poster....
Not really actually, I've been scripting for the whole of a week so forgive any obvious holes in my training.
I'm trying to make a cron script that will test wether or not I have internet access every 5 minutes or so. I've figured out how the every 5 minutes part works, but I don't know what command to use to check the internet connection status.
Using a ping command has been suggested to me, but how do I make the output from the ping command into a variable of some sort that I can use with an if statement?
Hopefully that all made sense....
Thanks in advance for the help,
I've made a similar script on my router, only that it checks for how much has been transferred as well. Anyway, here's my suggestion:
ping -c 1 -w 10 <IP of your ISP's gateway>
t=$(($(date +%s) - $t))
if [ $r -ne 0 ]; then
if [ $t -ge 5 ]; then
elif [ $t -ge 1 ]; then
if [ "$ostate" != $state ]; then
echo "$(date "+%b %d %H:%M:%S"): inet status is $state" >>/var/log/inet
echo $state >/var/run/inet