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

8,139

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
Share:
8,139

Related videos on Youtube

Sajinu
Author by

Sajinu

Updated on September 18, 2022

Comments

  • Sajinu
    Sajinu almost 2 years

    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.

  • Sajinu
    Sajinu about 8 years
    I am getting the output as pingable.
  • Sajinu
    Sajinu about 8 years
    but i need the output in my mail if one ip address check is failed. what can i do for that...
  • Cbhihe
    Cbhihe about 8 years
    @Sajinu: all you have to do to get email notification is: 1) Install an MTA (e.g.postfix) on yr box. 2) Configure it as send-only with an smtp server from yr favorite outside provider. 3) Replace one line (echo "$i not pingable" ) in heemayl's otherwise perfectly good answer with echo "$i not pingable" | mail -s "subject line" [email protected].--- Installing, configuring and running an MTA (e.g. postfix) is outside the scope of yr question. There are numerous answers and tutorials for that on AU and on the web.