先看一个命令:
[root@weblogic logs]# ls -c -
catalina.--.log
icatalina.--:-.out
icatalina.--:-.out
localhost_access_log.--.txt
host-manager.--.log
localhost.--.log
manager.--.log
catalina.out
catalina.--.log
icatalina.--:-.out
localhost_access_log.--.txt
host-manager.--.log
manager.--.log
localhost.--.log
catalina.--.log
catalina.--.log
localhost_access_log.--.txt
localhost.--.log
host-manager.--.log
manager.--.log
清理日志脚本:
[root@weblogic scripts]# cat clear_log_of_tomcat.sh
#!/bin/bash
log_path="/usr/local/tomcat/logs"
size_init=
for log in `find ${log_path} -type f -mtime +`;
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