nohup.out追加日志的文件,文件太大自动清零的脚本

 1 #!/bin/bash
 2 # clean the nohup.out file of list_domain
 3 # author by:guoqian
 4 # date:2018-06-19
 5 
 6 path="/home/weblogic/Oracle/Middleware/user_projects/domains/list_domain/bin"
 7 
 8 if [ $# -eq 0  ];then 
 9     cd $path
10     file_size=`du -sm nohup.out| awk '{print $1}'`
11 
12     if [ $file_size -ge 2000 ];then
13         /bin/cp /dev/null nohup.out
14         echo "$(date +%F' '%X) :The file size $file_size M , clean it over!" >> $path/clean_nohup.out.log
15     else
16         echo "$(date +%F' '%X) :The file size $file_size M , not clean it !" >> $path/clean_nohup.out.log
17     fi
18     exit 1
19 else
20     echo "Don't take parameters !"
21 fi

定时任务:0 0 * * 0,3 /home/weblogic/Oracle/Middleware/user_projects/domains/list_domain/bin/clean_nohup.out.sh > /dev/null 2>&1

1.此脚本用于清零自动追加日志的文件nohup.out

2.此脚本已在Red Hat Enterprise Linux Server release 5.6 (Tikanga)系统上经过测试通过。

3.此脚本写入crontab定时任务,每周三,周日晚上零点会自动检测,nohup.out文件大于2G时,会自动清零,且不会影响系统正常运行。

24小时绿色联系通道:

  QQ:418892106 

  E-mail:[email protected]

猜你喜欢

转载自www.cnblogs.com/guoqian/p/9203295.html