#!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或 執行自定義腳本的命令) ---------------------