[NBLUG/talk] shell scripting help

Sean seanvanco at gmail.com
Tue Jun 10 15:46:01 PDT 2008


I found that after about a half hour of sending the e-mail, and I also
cleaned up a few syntax errors. My current iteration is below, and it
does loop and terminate correctly. The only odd thing is that the time
between each ping is 37 seconds apart instead of 30.

If anyone has any idea why it's taking the extra 7 seconds, I'm
curious to see what I did wrong. Otherwise this will work for me.

Thanks!

#!/bin/bash
time="1"
while [ $time -le 180 ]

do

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

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

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

        #Commands here
        fi
done



More information about the talk mailing list