Results 1 to 2 of 2
I'm also having trouble getting a variable to keep a count. Here's what I have...
function IPTest {
failCount='0'
ipTest1=`fping $1`
[[ $ipTest1 =~ alive ]] && $failCount+=1
ipTest2=`fping $1`
...
- 08-11-2008 #1Just Joined!
- Join Date
- Apr 2008
- Posts
- 18
[SOLVED] Variable Counting
I'm also having trouble getting a variable to keep a count. Here's what I have...
function IPTest {
failCount='0'
ipTest1=`fping $1`
[[ $ipTest1 =~ alive ]] && $failCount+=1
ipTest2=`fping $1`
[[ $ipTest2 =~ alive ]] && $failCount+=1
ipTest3=`fping $1`
[[ $ipTest3 =~ alive ]] && $failCount+=1
ipTest4=`fping $1`
[[ $ipTest4 =~ alive ]] && $failCount+=1
ipTest5=`fping $1`
[[ $ipTest5 =~ alive ]] && $failCount+=1
echo $failCount
}
Now, when I run this, it properly checks the IP, but then does not add to $failCount. Instead, I get the error:
./ipMonitor: line 6: 0+=1: command not found
./ipMonitor: line 8: 0+=1: command not found
./ipMonitor: line 10: 0+=1: command not found
./ipMonitor: line 12: 0+=1: command not found
./ipMonitor: line 14: 0+=1: command not found
Help?
Thanks.
Mark Smith
- 08-11-2008 #2Just Joined!
- Join Date
- Apr 2008
- Posts
- 18
Solution found on http://tldp.org/LDP/abs/html/untyped.html.
ipTest1=`fping $1`
[[ $ipTest1 =~ unreachable ]] && let "failCount += 1"


