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..


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

with the ip list.txt file.


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

while IFS= read -r ip; do
    if ping -q -c2 "$ip" &>/dev/null; then
        echo "$ip is Pingable"
        echo "$i Not Pingable"
done <"$HOME"/iplist.txt
  • I am getting the output as pingable. – Sajinu Apr 19 '16 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 '16 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" username@domain.com.--- 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 '16 at 8:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.