[NBLUG/talk] shell scripting help

Sean seanvanco at gmail.com
Tue Jun 10 13:46:12 PDT 2008


I'm trying to set up a basic ping test, as my internet connection
appears to have trouble in the early morning. I need to prove that it
is occurring and track when it happens.

It's been a long time since I've done any scripting, especially with
loops, so I was hoping someone could help me. I can't get the looping
to work in the below code, which I've patched together using samples
from various websites. Could anyone tell me what I need to do? My
intent is to have cron run this and have the script terminate once the
number of loops has been reached.

Thanks!


#!/bin/bash
loops="1"
while [ loops != 180 ]

do

       if [ -z "$1" ]; then
       echo "Usage: `basename $0` ip-addr"
       exit 1;
       fi

       ping -c 1 -W 10 $1 &>/dev/null
       if [ $? -eq 0 ];
       #then / echo "Ping succeeded"
       # Commands here
       else
       echo "Ping failed" >> /var/log/ping_test.log
       date >> /var/log/ping_test.log

       #Commands here
       fi

       loops=`expr $loops + 1`
       sleep 30s

done



More information about the talk mailing list