Reputation: 19
#!/bin/bash
HOSTS="cyberciti.biz theos.in router"
COUNT=4
for myHost in $HOSTS
do
count=$(ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
if [ $count -eq 0 ]; then
# 100% failed
echo "Host : $myHost is down (ping failed) at $(date)"
fi
done
Upvotes: 0
Views: 95
Reputation: 17543
I've added some double quotes, this should do the trick:
#!/bin/bash
HOSTS="cyberciti.biz theos.in router"
COUNT=4
for myHost in $HOSTS
do
count=$(ping -c $COUNT "$myHost" | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
if [ "$count" -eq "0" ]; then
# 100% failed
echo "Host : $myHost is down (ping failed) at $(date)"
fi
done
Upvotes: 1