1

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.

1 Answer 1

2

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
3
  • I am getting the output as pingable.
    – Sajinu
    Apr 19, 2016 at 6:26
  • 1
    but i need the output in my mail if one ip address check is failed. what can i do for that...
    – Sajinu
    Apr 19, 2016 at 6:27
  • @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.
    – Cbhihe
    Apr 20, 2016 at 8:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .