检测主机存活

 

#!/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

 

posted @ 2018-08-27 19:19  LiShiChao  阅读(509)  评论(0编辑  收藏  举报