Testing multiple unix server Connectivity using pi

2019-09-06 00:04发布

问题:

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=XXXXXXXXXXXXX@domain.com
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

标签: shell unix