centos监控磁盘,自动发送报警脚本

公司最近又遇到一次因为磁盘满了导致的问题,讲道理这个完全可以避免嘛。搞个监控就好了。自动检测磁盘使用情况,提前预警。

磁盘检测脚本
#!/bin/sh
######################################################
# Create by VIM
# Author: ache
# Created Time : 2019年11月02日 星期日 08时24分56秒
# File Name: autoload.sh
# Description:磁盘检测脚本
######################################################

disk='vda1'
limit=10
mail=1751987128@qq.com
msg='请及时清理磁盘空间'
war=`df -h | grep $disk | tr '%' ' ' | awk '$5>'$limit'{print $1}' | wc -l`
if [ $war -gt 0 ]
then
	`echo $msg | mail -s 'disk check' $mail`
fi
配置邮件提醒

这里我是用mailx实现邮件发送的

// 安装mailx
yum install mail -y

// 生成证书
mkdir -p /root/.certs/
echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/qq.crt
certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
certutil -L -d /root/.certs
cd ~/.cert && certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu"  -d ./ -i qq.crt 

//   /etc/mail.rc追加内容
set from=1751987128@qq.com
set smtp=smtps://smtp.qq.com:465
set smtp-auth-user=1751987128@qq.com
set smtp-auth-password=xxxxxxxx//qq邮箱验证密钥
set smtp-auth=login
set ssl-verify=ignore
set nss-config-dir=/root/.certs

以上就完成了所有准备,可以修改脚本文件设置检测时间,无限循环,然后后台运行即可。或者也可以添加定时任务。

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

the ache

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值