Linux下每天自动执行查看磁盘剩余空间的shell文件
發表於 : 2012-07-03 08:13:30
http://wapiknow.baidu.com/question/1468 ... A%E9%97%B4
1. crontab -e
##编辑文件格式如下
0 6 * * * ~/check.sh
2.编辑check.sh 内容如下:
#!/bin/bash
mail=your_email@domain.com # 你的e_mail
code=`df | grep -c -E \(9[1-9]\%\)\|\(100\%\)` # 判断磁盘的占用有没有超过90%
if [ $code -gt 0 ]
then
df | mail -v -s "subject" $mail - ## 如果有,就发邮件,邮件内容为df 命令的输出(即:磁盘使用统计)
fi
#######################################################chech.sh 文件结束
3. 将check.sh移动到当前用户的home目录下
#######################################################
把你的邮件设置好,就能发了
4. chmod +x check.sh ## 设为可执行
5. /etc/init.d/crond restart ## 重起crond服务
1. crontab -e
##编辑文件格式如下
0 6 * * * ~/check.sh
2.编辑check.sh 内容如下:
#!/bin/bash
mail=your_email@domain.com # 你的e_mail
code=`df | grep -c -E \(9[1-9]\%\)\|\(100\%\)` # 判断磁盘的占用有没有超过90%
if [ $code -gt 0 ]
then
df | mail -v -s "subject" $mail - ## 如果有,就发邮件,邮件内容为df 命令的输出(即:磁盘使用统计)
fi
#######################################################chech.sh 文件结束
3. 将check.sh移动到当前用户的home目录下
#######################################################
把你的邮件设置好,就能发了
4. chmod +x check.sh ## 设为可执行
5. /etc/init.d/crond restart ## 重起crond服务