5、解压/opt/sendEmail-v1.56.tar.gz[root@localhost /]# tar xvf /opt/sendEmail-v1.56.tar.gz
6、测试脚本/报警邮件是否运行正常,可以看到,有2个分区是正常的,显示OK!,没有超过设置的阀值,有一个分区使用量超过阀值了,并自动成功发送了报警邮件,再去我设置的收件邮箱,可以看到已经收到了这封报警邮件:[root@localhost /]# sh /opt/disk_check.sh
OK! /dev/shm used 1%
OK! /boot used 12%
Reading message body from STDIN because the '-m' option was not used.
If you are manually typing in a message:
- First line must be received within 60 seconds.
- End manual input with a CTRL-D on its own line.
Jul 01 17:32:44 localhost sendEmail[5585]: Message input complete.
Jul 01 17:32:44 localhost sendEmail[5585]: Email was sent successfully!
7、最后,可以设置一个cron计划任务,让该脚本每隔1小时运行一次[root@webmail /]# crontab -e
在cron里添加下面一行即可*/60 * * * * /opt/disk_check.sh
原文链接:Linux下监控磁盘使用量并在超过阀值后自动发送报警邮件,转载请注明来源!
[root@VM_36_253_centos opt]# sh disk_check.sh
Reading message body from STDIN because the '-m' option was not used.
If you are manually typing in a message:
- First line must be received within 60 seconds.
- End manual input with a CTRL-D on its own line.Jan 12 10:47:06 localhost sendEmail[1528]: Message input complete.
disk_check.sh: line 5: 1528 段错误 /opt/sendEmail-v1.56/sendEmail -f $emailuser -t $sendto -s $emailsmtp -u $title -xu $emailuser -xp $emailpasswd
[root@iZ28kyy988gZ ~]# cd /opt
[root@iZ28kyy988gZ opt]# sh disk_check.sh
OK! /dev/shm used 0%
Reading message body from STDIN because the '-m' option was not used.
If you are manually typing in a message:
- First line must be received within 60 seconds.
- End manual input with a CTRL-D on its own line.Nov 08 10:40:23 iz28kyy988gz sendEmail[28632]: Message input complete.
Nov 08 10:41:23 iz28kyy988gz sendEmail[28632]: ERROR => Timeout while connecting to smtp.exmail.qq.com:25 There was no response after 60 seconds.
[root@iZ28kyy988gZ opt]#我的是腾讯企业邮箱,但看起来 一直连接超时。求大神帮忙看下