shell:实现linux服务器资源监控并发送告警邮件

1、安装方式

wget http://10.8.225.126/wsmonitor/install.sh;sh install.sh test@test.com

2、install.sh

#!/bin/sh
if [ $# -ne 1 ]; then
    echo "########################################################"
    echo "# 用法:sh install_monitor.sh 邮箱地址;                #"
    echo "# 如:sh install_monitor.sh chenjy@wangsu.com          #"
    echo "# 若邮箱地址多个用英文逗号分隔                         #"
    echo "########################################################"
    exit 1
fi
#对应目录放开权限,安装sendmail
/usr/bin/chattr -i /etc/shadow /etc/passwd /etc/gshadow /etc/group /etc/group-
mkdir /var/spool/clientmqueue;chmod 777 /var/spool/clientmqueue

for i in `seq 1 3`
do
    echo $i
    rpm -q --quiet sendmail
    if [ $? == 1 ]; then
        yum install -y sendmail
        if [ $? == 1 ]; then
            echo "######ERROR!sendmail install fail!######"
            echo "######Please try [yum install -y sendmail]######"
            exit
        fi
    fi
    rpm -q --quiet sendmail
    if [ $? == 0 ]; then
        service sendmail restart
        if [ $? == 1 ]; then
            echo "######ERROR!sendmail start fail!######"
            echo "######Please try [service sendmail restart]######"
            exit
        fi
        chkconfig --add sendmail
        break
    fi
    done
#下载监控脚本及启动后台执行
current=`date "+%Y-%m-%d %H:%M:%S"`
timestamp=`date -d "$current" +%s`
mkdir -p /usr/local/wsmonitor
mkdir -p /usr/local/wsmonitor/bak
for i in `seq 1 3`
do
    echo $i
#    if [ -f wsmonitor.sh ];then
#        mv /usr/local/wsmonitor/wsmonitor.sh /usr/local/wsmonitor/bak/wsmonitor.sh.$timestamp
#    fi
    
    wget http://10.8.225.126/wsmonitor/wsmonitor.sh -O /usr/local/wsmonitor/wsmonitor.sh
    wget http://10.8.225.126/wsmonitor/wsmonitor -O /etc/init.d/wsmonitor
    wget http://10.8.225.126/wsmonitor/ReadMe_wsmonitor.txt -O /usr/local/wsmonitor/ReadMe_wsmonitor.txt
    #替换监控脚本中的邮箱地址
    sed -i 's/MAILTO=chenjy@wangsu.com/MAILTO='$1'/g' /usr/local/wsmonitor/wsmonitor.sh
    #启动服务
    chmo
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值