zoukankan      html  css  js  c++  java
  • 自动删除日志

    删除6天以前的日志:

    find ./ -type f -mtime +6 -name "*.out" -exec rm -f {} ;

    参考:https://www.cnblogs.com/peida/archive/2013/03/25/2980121.html

               https://www.rxblog.xyz/linux-rm-crontab/

    find /opt/soft/log/ -mtime +30 -name "*.log" -exec rm -rf {} ;
    1,创建脚本,并分配权限
    touch /opt/soft/bin/auto-del-30-days-ago-log.sh chmod +x auto-del-30-days-ago-log.sh
    2,编辑脚本
    vi auto-del-30-days-ago-log.sh 编辑auto-del-30-days-ago-log.sh文件如下: #!/bin/sh find /opt/soft/log/ -mtime +30 -name "*.log" -exec rm -rf {} ; ok,保存退出(:wq)。
    3,添加任务
    ①执行:
    crontab -e 将auto-del-30-days-ago-log.sh执行脚本加入到系统计划任务,到点自动执行 ②输入: 10 0 * * * /opt/soft/log/auto-del-7-days-ago-log.sh >/dev/null 2>&1 这里的设置是每天凌晨0点10分执行auto-del-7-days-ago-log.sh文件进行数据清理任务了
    4,查询任务
    crontab -l

      

    #!/bin/bash
    #Clear tomcat expiration log
    #ENV
    WORKDATE="`date '+%Y-%m-%d.%H:%M:%S'`"
    
    #删除Tomcat日志,参数(天数)没传值时默认为60  
        if [ ! -n "$1" ];
        then
            day=60
        else
            day=$1
        fi
    #################### tomcat logs clear ####################
    TOMCAT_DIR=/usr/local/tomcat
    LOG_DIR=$TOMCAT_DIR/logs
    
    find $LOG_DIR/catalina.*             -type f -mtime +$day -exec rm {} ;
    find $LOG_DIR/host-manager.*         -type f -mtime +$day -exec rm {} ;
    find $LOG_DIR/localhost.*            -type f -mtime +$day -exec rm {} ;
    find $LOG_DIR/localhost_access_log.* -type f -mtime +$day -exec rm {} ;
    find $LOG_DIR/manager.*.log          -type f -mtime +$day -exec rm {} ;
    find $TOMCAT_DIR/webapps/logs/all.log.* -type f -mtime +$day -exec rm {} ;
    find $TOMCAT_DIR/webapps/logs/error.log.* -type f -mtime +$day -exec rm {} ;
    
    #################### tomcat logs clear ####################
    TOMCATF_DIR=/usr/local/tomcatadmin
    LOGF_DIR=$TOMCATF_DIR/logs
    
    find $LOGF_DIR/catalina.*             -type f -mtime +$day -exec rm {} ;
    find $LOGF_DIR/localhost.*            -type f -mtime +$day -exec rm {} ;
    find $LOGF_DIR/localhost_access_log.* -type f -mtime +$day -exec rm {} ;
    find $LOGF_DIR/manager.*.log          -type f -mtime +$day -exec rm {} ;
    #find $TOMCATF_DIR/webapps/logs/all.log.* -type f -mtime +$day -exec rm {} ;
    #find $TOMCATF_DIR/webapps/logs/error.log.* -type f -mtime +$day -exec rm {} ;
    
    #crontab -e Add: 1 0 * * * sh /usr/local/sbin/logClear_Tomcat.sh
    exit
    

      

    #!/bin/sh
    
    find /usr/local/tomcat-mail-provider-8081/logs/ -mtime +0 -name "*.log" -exec rm -rf {} ;
    find /usr/local/tomcat-mail-provider-8081/logs/ -mtime +0 -name "*.txt" -exec rm -rf {} ;
    
    
    find /usr/local/tomcat-mail-api-8082/logs/ -mtime +0 -name "*.log" -exec rm -rf {} ;
    find /usr/local/tomcat-mail-api-8082/logs/ -mtime +0 -name "*.txt" -exec rm -rf {} ;
  • 相关阅读:
    css3
    My97DatePicker时间控件使用
    练习中遇到的问题及知识点
    使用slideDown和slideUp做二级菜单时遇到的bug解决方法
    Google Chrome浏览器不支持小于12px的字体大小的问题及解决方法(我写的都不行)
    区别不同浏览器的兼容性
    img图片元素下多余空白解决方案
    gridview列绑定HyperLink
    vs设计界面出现“建控件时出错 响应在此上下文中不可用”
    SQL Server不能通过外部IP访问,解决方法
  • 原文地址:https://www.cnblogs.com/wanhua-wu/p/9282814.html
Copyright © 2011-2022 走看看