#!/bin/bash
date_start=`date|awk -F"[ :]" '{print $4*3600 + $5*60 +$6}'`
size=$(ls -l /usr/local/tomcat/logs/catalina.out | awk '{print $5}')
M=1024000
if [ $size -gt $M ]; then
echo "$(date +%Y%m%d-%H%M%S):you log file is larger then 10M" >>/home/tomcatlog/log.log
cp /usr/local/tomcat/logs/catalina.out /home/tomcatlog/$(date +%Y%m%d-%H%M).out
cat /dev/null > /usr/local/tomcat/logs/catalina.out
cd /home/tomcatlog
rm -rf catalina$(date -d -20day +%Y%m%d).out
else
echo "$(date +%Y%m%d-%H%M%S):you log file is smaller then 10M " >>/home/tomcatlog/log.log
fi
date_end=`date|awk -F"[ :]" '{print $4*3600 + $5*60 +$6}'`
time=`expr "$date_end" - "$date_start"`
echo $(date +%Y%m%d) >> /home/tomcatlog/log.log
echo workingtime=$time >> /home/tomcatlog/log.log
转载于:https://blog.51cto.com/snbolinux/1052165