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=[email protected]
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 [email protected]
set smtp=smtps://smtp.qq.com:465
set [email protected]
set smtp-auth-password=xxxxxxxx//qq邮箱验证密钥
set smtp-auth=login
set ssl-verify=ignore
set nss-config-dir=/root/.certs

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

发布了51 篇原创文章 · 获赞 2 · 访问量 6015

猜你喜欢

转载自blog.csdn.net/weixin_44600422/article/details/102879033
今日推荐