背景:
公司要求刪除2天之前的備份檔案及所有日誌,免得把硬碟給整爆了,上伺服器看了下,居然都有3個月的備份沒有清理了!
su root
citics@200
cd /
du -sh *
cd /dbbak
du -sh *
cd /rman
du -sh *
cd data
du -sh *
125執行程式:
vim delbkp.sh
find /dbbak/rman/data -mtime +2 -type f -name '*' -exec rm -f {} \; --刪除兩天前的資料
su root
citics@200
chmod 777 /opt/delbkp.sh --給檔案授權
crontab –e
1 0 * * * /opt/delbkp.sh --0點執行 ,分 時 日 月 周 (周指星期幾)
tail -fn 100 /var/log/cron --檢視執行日誌情況
附:1、編寫清理日誌指令碼clearlog.sh
#!/bin/sh
find /newdisk/ss/mg/log -mtime +1 -name "*.log" -exec rm {} \;
find /newdisk/ss/msu/log -mtime +1 -name "*.log" -exec rm {} \;
2、給指令碼增加可執行許可權
我的指令碼預設放在/opt/下
chmod 755 /opt/clearlog.sh
3、加入定時執行任務,定時執行指令碼
切換到root使用者
使用crontab 命令建立定時執行
命令:crontab –e
加入行:*/10 * * * * /opt/clearlog.sh
改行含義為每10分執行/usr/clearlog.sh指令碼一次
查詢程序:
ps -ef | grep 程序名
crontab計畫任務
編輯crontab檔案 crontab e 檢視crontab日誌 tail 100f var log cron 基本格式 command 分 時 日 月 周 命令 第1列表示分鐘1 59 每分鐘用 或者 1表示 第2列表示小時1 23 0表示0點 第3列表示日期1 31 第4列表示月份1 12 第...
crontab計畫任務
crontab是linux下定製計畫任務的工具,其使用方便,是居家旅行 定時搞事的必備神器。本篇記錄下crontab使用方法,以及注意坑點。command一般寫計畫任務,都是執行crontab e然後寫入計畫任務,儲存退出即可。sleep 10 每10s執行一次。30 21 usr local et...
Crontab計畫任務
crontab定義 crontab是乙個用於設定週期性被執行的任務的工具,被週期性執行的任務我們稱為cron job,週期性執行的任務列表我們成為cron table。檢查crontab工具是否安裝 crontab l 安裝cron服務 yum install vixie cron yum inst...