Linux下每天自动执行查看磁盘剩余空间的shell文件

回覆文章
yehlu
Site Admin
文章: 3244
註冊時間: 2004-04-15 17:20:21
來自: CodeCharge Support Engineer

Linux下每天自动执行查看磁盘剩余空间的shell文件

文章 yehlu »

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服务
yehlu
Site Admin
文章: 3244
註冊時間: 2004-04-15 17:20:21
來自: CodeCharge Support Engineer

Re: Linux下每天自动执行查看磁盘剩余空间的shell文件

文章 yehlu »

http://forum.icst.org.tw/phpbb/viewtopi ... 16&t=15443

代碼: 選擇全部

#!/bin/sh
partition="/"
free_space=`df --block-size=1GB -P ${partition}| awk '{print $4}' | tail -n 1`
threadhold=10
mail_body="[資安論壇] 硬碟空間不足"
if [ ${free_space} -lt ${threadhold} ]; then
  echo -e ${mail_body} |mutt -s "Caution! 磁區空間已達設定threashold [ ${free_space}/${threadhold} ]" kido@htx -a "${outputfile}"
fi
回覆文章

回到「Linux」