tomcat日誌切割指令碼 cronolog

2020-08-11 14:52:46

#################yum (rpm or tar skip)
yum -y install cronolog
which cronolog
###/usr/sbin/cronolog successful
logdir=` which cronolog `
catalinadir=` find / -name catalina.sh | awk -F/catalina.sh ‘{print$1}’\ `
sh $catalinadir/shutdown.sh
sed -i ‘s#>> 「$CATALINA_OUT」 2>&1 「&」#2>&1 |$logdir 「$CATALINA_BASE/logs/catalina-%Y-%m-%d.out」 &#g’ $catalinadir/catalina.sh
sh $catalinadir/start.sh

###################clean log
cat >> /opt/clean_log.sh <<EOF
#!/bin/bash
find /usr/local/tomcat/logs/ -name 「.」 -type f -mtime +2 -exec rm -f {} ;
EOF
chmod 777 /opt/clean_log.sh
echo " 30 0 * * * sh /opt/clean_log.sh" >> /etc/crontab
systemctl restart crond.service