定时清理日志
2016-05-05 13:56
183 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/zte619801897/article/details/51322367
crontab -e
0 5 * * * /home/deploy/bin/log-clear.sh
0 5 * * * /aaa/bbb/ccc/MyProject/work/bin/log-clear.sh
查看
crontab -l
脚本:log-clear.sh
#!/bin/bash cd `dirname "$0"` GATE_LOGS_DIR="/aaa/bbb/app/Search.Antibot.Gate/logs" find $GATE_LOGS_DIR \( -name '*.log*' \) -mtime +${log_alive_days:=6} -delete; # clear the log files that generated by process and greater than 1G,but won't be deleted for logfile in $( find $GATE_LOGS_DIR \( -name "*.log*" \) -size +1048576k) do echo 'log size more than 1G,just clear it.................' > "$logfile" done exit 0
脚本:log-clear-new.sh
#!/bin/bash cd `dirname "$0"` if ! . ./env.sh then exit 1 fi find $LOGS_DIR \( -name '*.log*' \) -mtime +${log_alive_days:=29} -delete; # for start log and GC log, keep only the last 3 days rm -f $(ls -t ${LOGS_DIR}/start.${app_name}.*.log | tail -n +4) rm -f $(ls -t ${LOGS_DIR}/${app_name}_gc.*.log | tail -n +4) # clear the log files that generated by process and greater than 1G, but won't be deleted for logfile in $( find $LOGS_DIR \( -name "start.*.log" -o -name "${app_name}_gc.*.log" \) -size +1048576k) do echo_t 'log size more than 1G,just clear it.................' > "$logfile" done exit 0
脚本:env.sh
#!/bin/bash . ./global.sh if readlink -f "$0" > /dev/null 2>&1 then script_name=`readlink -f "$0"` else script_name="$0" fi local_bin_dir=`dirname "$script_name"` LOGS_DIR="$local_bin_dir/../../logs" app_name="myapp"
步骤:
1.修改
vim log-clear.sh
2.转格式
dos2unix log-clear.sh3.加权限
chmod +x log-clear.sh4.设置定时清理
修改,对应脚本存放的具体路径crontab -e
0 5 * * * /home/deploy/bin/log-clear.sh
0 5 * * * /aaa/bbb/ccc/MyProject/work/bin/log-clear.sh
查看
crontab -l
相关文章推荐
- Linux定时清理游戏log及mysql定时任务删除游戏日志数据
- 服务自动拉起,定时日志清理,数据统计的shell脚本
- Linux应用--日志定时清理
- mysql 日志爆满,删除日志文件,定时清理日志
- Exchange 2007 SP1 如何定时清理日志???
- shell实战编程--定时清理日志shell编程
- Linux使用定时任务每周定时清理45天以前日志
- linux shell脚本定时清理tomcat日志文件(初稿)
- linux日志定时清理
- MySQL数据的binlog处理方法 日志定时清理
- Linux日志定时清理
- C# 启动WinRAR定时执行Web日志压缩清理
- 可定时执行的Web日志自动压缩清理程序
- tomcat日志文件定时清理备份
- linux下定时清理日志任务
- Linux使用定时任务每周定时清理45天以前日志
- 定时删除日志文件---linux定时清理日志
- Jetty6 设置定时自动清理日志
- aix系统使用定时任务每天备份清理nohup日志操作步骤
- 定时清理,日志文件