压缩日志脚本
创建脚本文件
cd /root
touch tarLog.sh
chmod 777 /root/tarLog.sh
tarLog.sh文件内容
#! /bin/bash
#日志所在目录
DEST_DIR=/home/log
cd $DEST_DIR
#产生压缩文件的后缀加上日期
time=`date +"%Y-%m-%d" -d "-1days"`
#日志文件名
log_file=log.$time.log
if [ ! -f "$log_file" ]; then
exit 0
fi
gzip $log_file
linux下设置定时任务
crontab -e #编辑表达式
0 8 * * * /root/tarLog.sh #每天8点定时压缩
crontab -l #查看定时任务
世间一切,唯我所用,非我所有!