Ubuntu – I need a script file for checking (ping) 3 ip address are working or not

bashcronmailpingscripts

I need to create a script for checking (ping) 3 ip address are working or not.
using the crone tab and i do want to know how is it working.
I was used a script using a test file, but i need to get the alert message in my mail af any one ip address is down..
please help me anyone.
thanks in advance

i have used this script..

#!/bin/bash

for i in $( cat $HOME/iplist.txt )
do
ping -q -c2 $i > /dev/null
if [ $? -eq 0 ]
then
echo $i "Pingable"
else
echo $i "Not Pingable"
fi
done

with the ip list.txt file.

Best Answer

  • Use a while loop with read to get each IP address and then use ping:

    #!/bin/bash
    while IFS= read -r ip; do
        if ping -q -c2 "$ip" &>/dev/null; then
            echo "$ip is Pingable"
        else
            echo "$i Not Pingable"
        fi
    done <"$HOME"/iplist.txt