I need a script that will ping two hosts and execute a command depending on their status.
i.e
#!/bin/bash
HOSTS="1.1.1.1 2.2.2.2"
for myHost in $HOSTS
do
fping $myHost > /tmp/ping.log
if [ $(grep -c "1.1.1.1 is unreachable" "/tmp/echo.log") -eq 1 ]; then
echo "1.1.1.1 is down"
else
if [ $(grep -c "2.2.2.2 is alive" "/tmp/echo.log") -eq 1 ]; then
echo "2.2.2.2 is alive"
fi
fi
done
then i need to have if 1.1.1.1 doesn't respond and 2.2.2.2 does then do command and the other way round i.e if 1.1.1.1 responds and 2.2.2.2 doesn't then do command.