• linux系统定时任务定期清楚nohup日志


    项目开发中,经常会使用nohup 命令启动应用,但项目产生日志过多,没几天硬盘空间就满了,设置一个定期任务清理日志则能解决次问题,操作如下

    1.编写执行脚本

    #!/bin/bash
    # clean the nohup.out of book ,info,server
    # date:2020-08-13

    path1="/weblogic/stock_domain"
    path2="/weblogic/bbsbook_domain"
    path3="/weblogic/bbsinfo_domain"
    if [ $# -eq 0 ];then
    cd $path1
    file_size=`du -sm nohup.out | awk '{print $1}'`

    if [ $file_size -ge 1 ];then
    /bin/cp /dev/null nohup.out
    echo "$(date +%F' '%X) :The file size $file_size M , clean it over!" >> /weblogic/stock_domain/clean_nohup.out.log
    else
    echo "$(date +%F' '%X) :The file size $file_size M , not clean it !" >> /weblogic/stock_domain/clean_nohup.out.log
    fi
    cd $path2
    file_size=`du -sm nohup.out | awk '{print $1}'`

    if [ $file_size -ge 1 ];then
    /bin/cp /dev/null nohup.out
    echo "$(date +%F' '%X) :The file size $file_size M , clean it over!" >> /weblogic/bbsbook_domain/clean_nohup.out.log
    else
    echo "$(date +%F' '%X) :The file size $file_size M , not clean it !" >> /weblogic/bbsbook_domain/clean_nohup.out.log
    fi
    cd $path3
    file_size=`du -sm nohup.out | awk '{print $1}'`

    if [ $file_size -ge 1 ];then
    /bin/cp /dev/null nohup.out
    echo "$(date +%F' '%X) :The file size $file_size M , clean it over!" >> /weblogic/bbsinfo_domain/clean_nohup.out.log
    else
    echo "$(date +%F' '%X) :The file size $file_size M , not clean it !" >> /weblogic/bbsinfo_domain/clean_nohup.out.log
    fi
    else
    echo "Don't take parameters !"
    fi

    --------------------------------------------------------------------

    备注:path1,path2,path3 路径 为需要清理nohup.out日志的三个路径

    2. crontab -e 创建定时任务

    添加以下内容


    59 11 * * * ./etc/profile;sh /weblogic/stock_domain/ClearNohup.sh

  • 相关阅读:
    Template-网页模板:百科
    POJ 1743 Musical Theme(后缀数组)
    android ProgressBar 样式讲解
    opencv显示鼠标所在位置的rgb值
    JSU 2013 Summer Individual Ranking Contest
    spring mvc 中文乱码 post与get的方法解决
    iphone/ipad实现自定义的开关UISwitch(continuous,clipsToBounds,userInteractionEnabled属性)
    hdu 2093
    poj 1180 斜率优化dp
    太空飞行计划问题
  • 原文地址:https://www.cnblogs.com/liuzhenguo/p/13498550.html
Copyright © 2020-2023  润新知