Testing multiple unix server Connectivity using ping command and send mail the hostname/ip-address of the servers if any hosts are unreachable
There is file host.txt which contain the list of the servers we want to ping
for e.g
www.abc.domain01.com
www.abc.domain02.com
www.abc.domain03.com
www.abc.domain04.com
in this case i'm considering there are total four servers ; but it can be 100 servers i know how to check the connectivity of multiple servers but i don't know how to get the mail if particular server(s) is unreachable MY CODE IS
[email protected]
for i in $(cat host.txt)
do
ping -c4 $i
if [ $? -ne 0 ]
then
echo "$i is unreachable"|mail -s "ping alert" $email
fi
done
suppose server www.abc.domain01.com is unreachable so i want see the output in my mail like www.abc.domain01.com
echo "test from my server" | mail -s "mailTest" [email protected]work? If not, thensendmailprobably isn't work, or there are rules that are blocking your message or numerous other things. Real error messages are best in your question. Good luck.$?, you can redirectpingoutput to /dev/null, i.e.ping -c4 $i 2>/dev/null. Checkman ping. maybe your version has something like-sfor silent.