shell脚本 --内存监控自动发邮件告警

内存监控自动发邮件告警

  • 【shell要求】
    用shell写一个内存监控脚本,使用超过80%并发邮件告警

  • 【shell思路】
    1、思路:free
    free -m

                 total       used        free       shared       buff/cache          available
    Mem:         3770         219        3170          11              381             3325
    Swap:        2047           0         2047
    

##Mem:内存的使用情况总览表。
##totel:机器总的物理内存 单位为:M
##used:用掉的内存。
##free:空闲的物理内存。

2、算取百分比

3、比对做出判断

  • 【shell配置】

    #!/bin/bash
    A=`free -m | grep "^Mem" | awk '{print $2}'`
    B=`free -m | grep "^Mem" | awk '{print $3}'`
    C=`free -m | grep "^Mem" | awk '{print $4}'`
    D=`free -m | awk '/Mem/ {print int($3/$2*100)}'`
    if [ $D -gt 1 ];then
     /opt/sendEmail.sh [email protected] "内存警告" "总内存为:$A M 已使用内存:$B M 空间内存:$C M   内存使用率已达$D % , 请尽快处理"        #####xxxxxxxxx填写想发送的QQ
    fi
    

————————————————————————————————————————
到此结束,感谢观看

猜你喜欢

转载自blog.csdn.net/XCsuperman/article/details/108307200