[root@centos7 /data]#vim checkdisk.sh #!/bin/bash WARNING=10 MAIL=root@localhost df |sed -rn '/^/dev/sd/s#^([^[:space:]]+).* ([[:digit:]]+)%.*#1 2#p'|while read diskpart used;do if [ $used -gt $WARNING ];then echo $diskpart will be full,used:$used% | mail -s "diskcheck_alert" $MAIL fi done
为脚本添加执行权限
[root@centos7 /data]#chmod +x checkdisk.sh
添加定时任务
[root@centos7 /data]#crontab -e */10 * * * * /bin/bash /data/checkdisk.sh &> /dev/null