先看一個命令:
[root@weblogic logs]# ls -c -1 catalina.2018-01-02.log icatalina.2018-01-02:21-07.out icatalina.2018-01-02:20-56.out localhost_access_log.2018-01-02.txt host-manager.2018-01-02.log localhost.2018-01-02.log manager.2018-01-02.log catalina.out catalina.2017-12-15.log icatalina.2017-12-15:15-39.out localhost_access_log.2017-12-15.txt host-manager.2017-12-15.log manager.2017-12-15.log localhost.2017-12-15.log catalina.2017-12-10.log catalina.2017-12-06.log localhost_access_log.2017-12-06.txt localhost.2017-12-06.log host-manager.2017-12-06.log manager.2017-12-06.log
清理日誌指令碼:
[root@weblogic scripts]# cat clear_log_of_tomcat.sh #!/bin/bash log_path="/usr/local/tomcat/logs" size_init=102400 for log in `find ${log_path} -type f -mtime +10`; do echo $log size=`ls -l $log|awk '{print $5}'` if [ $size -gt ${size_init} ];then echo "$log file is too large,start to clear" rm -f $log fi done