Chinaunix

标题: 求一个监控磁盘空间的shell script! [打印本页]

作者: iolia131    时间: 2006-11-17 09:38
标题: 求一个监控磁盘空间的shell script!
能不能有一个这样的shell script:
当某个磁盘分区(比如hda4)的使用率到达95%,系统自动发送邮件通知管理员!
作者: gucuiwen    时间: 2006-11-17 10:31
#!/bin/bash

RESULT=$(df |grep "/dev/" |awk '{print $5}'|sort -nr |head -1|tr -d "%")
if [ "$RESULT" -gt "95" ];
then
     echo "disk usage of server `hostname` is nearly full !!" |mail -s "Server Warning" root@abc.com
fi

exit 0

把这个脚本放在crontab里周期性执行就可以了。
如果运行脚本的服务器上没有mail smtp服务,那么要在mailrc中设置好mailrc否则发邮件发不出去。

set smtp=smtp.163.com
set smtp-auth=login
set smtp-auth-user=username
set smtp-auth-password=password

[ 本帖最后由 gucuiwen 于 2006-11-17 10:40 编辑 ]
作者: gig2600    时间: 2006-11-17 11:16
请问mailrc是什么的配置文件? mail命令的配置文件吗?
mailrc的路径在什么地方呢?
如果需要用到mailrc这个配置文件,那么mail命令的具体写法是怎么样的呢




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2