linux的简单日志定时压缩脚本

第一步:

添加定时任务:
crontab -e

然后添加一行:

每天5点30运行
30 5 * * * /home//script/log_clean.sh

(其时间有分、时、日、月、周

 第二步:

编写log_clean.sh,内容为:

#! /bin/sh
cd /home/nea/log
#压缩3天前文件
find ./ -name "*" -type f -mtime +3 -exec gzip {} \;
#删除90天前文件
find ./ -name "*" -type f -mtime +90 -exec rm -rf {} \;

posted @ 2020-12-02 17:46  xujf  Views(638)  Comments(0Edit  收藏  举报