1 Shell脚本案例 删除超过30天的日志文件
#!/bin/bash log_path=/mnt/software/apache-tomcat-9.0.0.M22/logs d=`date +%Y-%m-%d` d90=`date -d‘30 day ago‘ +%Y-%m-%d` #cd ${log_path} && cp catalina.out $log_path/cron/catalina.out.$d.log #echo > catalina.out rm -rf $log_path/catalina.out.${d90}*.log rm -rf $log_path/localhost.${d90}*.log rm -rf $log_path/student/talkilla-student*.${d90}*.log rm -rf $log_path/wechat/talkilla-wechat*..${d90}*.log rm -rf $log_path/teacher/talkilla-teacher*.${d90}*.log rm -rf $log_path/consultant/talkilla-consultant*..${d90}*.log rm -rf $log_path/admin/talkilla-admin*.${d90}*.log
2 配置定时执行,每天23点30分执行一次
crontab -e 30 23 * * * root sh /mnt/software/shell/clear-tomcat-log.sh
原文地址:https://www.cnblogs.com/QuestionsZhang/p/10329577.html
时间: 2024-10-10 08:23:03