Results 1 to 2 of 2
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 09-11-2003 #1
- Join Date
- Sep 2003
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,
- 09-12-2003 #2
- Join Date
- Oct 2001
- Täby, Sweden
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:
#!/bin/sh t=$(date +%s) ping -c 1 -w 10 <IP of your ISP's gateway> r=$? t=$(($(date +%s) - $t)) if [ $r -ne 0 ]; then state=DOWN else if [ $t -ge 5 ]; then state=VERYSLOW elif [ $t -ge 1 ]; then state=SLOW else state=UP fi fi ostate=$(cat /var/run/inet) if [ "$ostate" != $state ]; then echo "$(date "+%b %d %H:%M:%S"): inet status is $state" >>/var/log/inet echo $state >/var/run/inet fi