检测主机存活
#!/bin/bash ip_list=/opt/shell/ip.txt email=xxxxx@163.com status_log=/opt/shell/status.log sendmail (){ echo " ---------------- `date +%F_%H:%M` ------------------ 主机:$1 无法访问 " > $status_log mail -s "主机状态" $email < $status_log } for i in `cat "$ip_list"` do host_status=`nmap -n -sn $i|grep -wc 'Host is up'` if [ $host_status -eq 0 ];then sendmail $i fi done