zoukankan      html  css  js  c++  java
  • Linux服务器监控SHELL脚本(自动发邮件)(转)

    脚本根据网上流传的手机版和MSN发信息版本改造
    通过mail命令发送邮件

    前提是监控服务器要安装有MTA,如sendmail,exim4,postfix

    主http.sh脚本内容

    #!/bin/bash
    LANG=C
    server_all_list=(server1_IP:port server2_IP:port...)
    date=$(date -d "today" +"%Y-%m-%d_%H:%M:%S")

    server_all_len=${#server_all_list[*]}

    i=0
    while [ $i -lt $server_all_len ]
    do
    server_ip=$(echo ${server_all_list[$i]} | awk -F ':' '{print $1}')

    server_port=$(echo ${server_all_list[$i]} | awk -F ':' '{print $2}')

    if ping -c 1 $server_ip
    then
    echo "服务器${server_ip}连接ping正常!"
    else
    echo "服务器${server_ip}无法Ping通!"
    echo "服务器${server_ip}无法连接,请检查 故障描述:无法ping通 日期:${date}" | mail -s "服务器监控系统,请不要回复" your@xxx.com -a "Content-type: text/html; charset=utf-8" -- -f server_report@yyy.com
    fi
    let i++
    done

    再创建一个循环脚本mon.sh

    #!/bin/bash

    while true

    do

    /bin/bash /root/http.sh >/dev/null 2>&1

    sleep 60

    done

    最后创建一个启动脚本start_report.sh

    只用一行

    nohup /root/mon.sh > /dev/null 2>&1 &

    aliyun活动 https://www.aliyun.com/acts/limit-buy?userCode=re2o7acl
  • 相关阅读:
    手把手教您玩转信用卡 如何“以卡养卡”合法“套现”
    267家已获第三方许可机构名单查询
    C#生成图片验证码
    File I/O
    文件上传代码
    集合框架
    接口
    多态
    封装
    jsp做成mvc模式的代码
  • 原文地址:https://www.cnblogs.com/wangbin/p/1898674.html
Copyright © 2011-2022 走看看