#!bin/bash #author:jonychen DATE=$(date +%Y-%m-%d) echo start ${DATE} task aa=`df -h | awk '{print$5}'|sed -n "2, 1p"` bb=`echo ${aa%\%*}` cc=70 echo ${bb} if [ ${bb} -ge ${cc} ] then echo start delete big file mubiao=(`ls /opt/log/*.log* /opt/log/resin-log/*.log*`) for i in ${mubiao[*]} do echo "" > ${i} rm -rf ${i} done #find /opt/log/ -size +50M -exec rm {} \; #find /opt/log/resin-log/ -size +50M -exec rm {} \; echo end delete else echo no file need to delete fi echo end ${DATE} task
添加定时任务:shell
crontab -ebash
加:0 0 */4 * * cd /home/script && sh free_space.sh >> /tmp/free_space.log 2>&1 & (每4天清理一次)this
#!/bin/bash
#author:jonychen
disk_sda2=df -h |sed -n '2p'|awk '{print $5}' |cut -f 1 -d '%' if ((disk_sda2>80)); then echo "this is error" echo date"192.168.40.1061 this is over 80%" |mail -s "disk over 80%,script: sh /home/script/free_space.sh" 1232332@qq.com else echo "this is ok" fi
添加定时任务:spa
crontab -ecode
加:*/30 * * * * /App/script/monitor_disk_space.sh(每30分钟检查一次)blog
minute hour day month dayofweek commandcrontab
分钟 小时 天 月 星期ip
* 表明任意值 */5 表明每五个单位时间执行一次it
minute - 从0到59的整数 class
hour - 从0到23的整数
day - 从1到31的整数 (必须是指定月份的有效日期)
month - 从1到12的整数 (或如Jan或Feb简写的月份)
dayofweek - 从0到7的整数,0或7用来描述周日 (或用Sun或Mon简写来表示)
command - 须要执行的命令(可用as ls /proc >> /tmp/proc或 执行自定义脚本的命令) ---------------------