美文网首页
linux定时删除日志脚本

linux定时删除日志脚本

作者: zhong | 来源:发表于2018-03-26 15:45 被阅读0次

一、思路

定时删除日志,其实分为两个过程:

  1. 查找符合条件的日志并删除
  2. 定时
    过程1需要写一个查找脚本,过程2需要用到linux的crontab

二、查找并删除

# vim delete-logs.sh

删除指定目录下7天以上的日志文件:

find /home/trs/trswcmv7/Tomcat/logs -name "host-manager.*" -mtime +7 -exec rm -rf {} \;
find /home/trs/trswcmv7/Tomcat/logs -name "localhost.*" -mtime +7 -exec rm -rf {} \;
find /home/trs/trswcmv7/Tomcat/logs -name "manager.*" -mtime +7 -exec rm -rf {} \;
find /home/trs/trswcmv7/Tomcat/logs -name "catalina.*" -mtime +7 -exec rm -rf {} \;
find /home/trs/trswcmv7/Tomcat/logs -name "localhost_access_log*" -mtime +7 -exec rm -rf {} \;

find /home/data/bak/wcm -type d -mtime +120 -exec rm -rf {} \;

# chmod +x delete-logs.sh

三、linux定时任务

# crontab -e

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# | .-------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
  1 0 * * * /usr/sbin/ntpdate 10.11.4.1 &
 55 23 * * * /home/trs/delete-outofdate-logs.sh

完工

相关文章

  • linux定时删除日志脚本

    一、思路 定时删除日志,其实分为两个过程: 查找符合条件的日志并删除 定时过程1需要写一个查找脚本,过程2需要用到...

  • linux 下创建定时任务

    本文以定时删除linux某些系统日志为例,创建每隔半小时删除指定文件(一些日志文件持续增长) 1、创建自动执行脚本...

  • Windows和Linux下删除某天前日志文件的脚本

    无论是在windows下还是linux下,很多的日志文件如果不定时删除会充满硬盘,所以可以分别写个脚本定时处理一下...

  • nginx日志切割脚本

    nginx日志切割脚本,在Linux上部署成crond定时任务,0点执行会进行日志切割

  • Linux 定时删除日志

    导语 项目中会生成各种各样的日志,随着时间的推移,日志也是越来越多。超过一定时间的日志就没有了参考的价值,也会占用...

  • nginx日志切割,删除最近7天日志

    方案名简述手写sh脚本方案自己手写sh脚本,切割以及删除日志,crontab每晚定时执行logrotate 方案利...

  • 方案集

    定时器 1、Linux,Crontab,周期运行Shell脚本,可以用于清理日志详见:https://www.ji...

  • shell 脚本删除过期文件

    1.定时删除7天之前的文件2.使用shell脚本定时删除 脚本内容 脚本存放目录 将脚本配置到系统调度中 编辑调度...

  • nginx日志切割并删除N天之前的日志

    日志脚本 添加定时任务

  • 定时删除脚本

    windows:find /d/ScriptTest -cmin +60 -type d -exec /c/Pro...

网友评论

      本文标题:linux定时删除日志脚本

      本文链接:https://www.haomeiwen.com/subject/xmyrcftx.html