利用ansible监控空远程机连通性的shell脚本

#!/bin/bash
#by fuqiang
#2018-08-13

cd /home/ansible/
ansible vpn -m ping  > log/ping-vpn.log
num=`cat log/ping-vpn.log | grep -o 'SUCCESS' | wc -l`

if [ $num -ne 2 ];then 
   sendEmail -f [email protected] -t [email protected] -s smtp.139.com -u "vpn-ssr machines ping errors!" -xu [email protected] -xp harry*** -m "1.vpn-ssr machines ping errors; 2.Please to see the mail attachment file." -a /home/ansible/log/ping-vpn.log
fi

if [ $num -eq 2 ];then 
   echo 'No errors!' > /home/ansible/log/NoErrors-ping-vpn.log
fi

猜你喜欢

转载自blog.csdn.net/kevinsingapore/article/details/81661490