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.

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