Our previous scripts were commands that ran quickly to completion. Here is an example of a script that runs until you decide to terminate it. Note that if no parameters are required, a Usage
section is probably not needed (but be sure to state what the script does in the comment section).
This script monitors the state of the network connection by pinging the provider once a minute. Failures are logged to a file.
The following is the program listing:
1 #!/bin/sh 2 # 3 # Check network once a minute and log failures to a file 4 PROVIDER=192.168.1.102 5 tput clear 6 while [ 1 ] 7 do 8 echo Written by Jim Lewis 2/21/2007 9 echo Pinging $PROVIDER 10 ping -c 1 $PROVIDER 11 rc=$? 12 if [ $rc -ne 0 ] ; then 13 echo Cannot ping $PROVIDER 14 date >> log1.txt 15 echo Cannot ping $PROVIDER >> log1.txt 16 fi 17 sleep 60 18 done