前端创建shell脚本:
1、创建脚本
touch /home/sunline/sunline-tomcat/apache-tomcat-7.0.81/logs/auto-del-15-days-ago-log.sh
2、使脚本变可执行状态
chmod +x /home/sunline/sunline-tomcat/apache-tomcat-7.0.81/logs/auto-del-15-days-ago-log.sh
3、编辑脚本
cd /home/sunline/sunline-tomcat/apache-tomcat-7.0.81/logs/
vi auto-del-15-days-ago-log.sh
#!/bin/sh
find /home/sunline/sunline-tomcat/apache-tomcat-7.0.81/logs -mtime +15 -name "manager.*.log" -exec rm -rf {} \;
find /home/sunline/sunline-tomcat/apache-tomcat-7.0.81/logs -mtime +15 -name "localhost_access_log.*.txt" -exec rm -rf {} \;
find /home/sunline/sunline-tomcat/apache-tomcat-7.0.81/logs -mtime +15 -name "localhost.*.log" -exec rm -rf {} \;
find /home/sunline/sunline-tomcat/apache-tomcat-7.0.81/logs -mtime +15 -name "host-manager.*.log" -exec rm -rf {} \;
find /home/sunline/sunline-tomcat/apache-tomcat-7.0.81/logs -mtime +15 -name "catalina.*.log" -exec rm -rf {} \;
:wq(保存退出)
// 干掉15天之前的日志文件
4、将auto-del-15-days-ago-log.sh执行脚本加入到系统计划任务,到点自动执行
crontab -e
// >/dev/null 2>&1是抛向黑洞的意思QAQ
10 0 15 * * /home/sunline/sunline-tomcat/apache-tomcat-7.0.81/logs/auto-del-15-days-ago-log.sh >/dev/null 2>&1
5、查看有哪些定时任务
crontab -l
后端端创建shell脚本:
1、创建脚本
touch /home/sunline/apps/calcservice/logs/auto-del-15-days-ago-log.sh
touch /home/sunline/apps/docprintservice/logs/auto-del-15-days-ago-log.sh
touch /home/sunline/apps/loginservice/logs/auto-del-15-days-ago-log.sh
touch /home/sunline/apps/payservice/logs/auto-del-15-days-ago-log.sh
touch /home/sunline/apps/saveservice/logs/auto-del-15-days-ago-log.sh
touch /home/sunline/apps/searchservice/logs/auto-del-15-days-ago-log.sh
touch /home/sunline/apps/underwriteservice/logs/auto-del-15-days-ago-log.sh
touch /home/sunline/apps/uploadphotoservice/logs/auto-del-15-days-ago-log.sh
2、使脚本变可执行状态
chmod +x /home/sunline/apps/calcservice/logs/auto-del-15-days-ago-log.sh
chmod +x /home/sunline/apps/docprintservice/logs/auto-del-15-days-ago-log.sh
chmod +x /home/sunline/apps/loginservice/logs/auto-del-15-days-ago-log.sh
chmod +x /home/sunline/apps/payservice/logs/auto-del-15-days-ago-log.sh
chmod +x /home/sunline/apps/saveservice/logs/auto-del-15-days-ago-log.sh
chmod +x /home/sunline/apps/searchservice/logs/auto-del-15-days-ago-log.sh
chmod +x /home/sunline/apps/underwriteservice/logs/auto-del-15-days-ago-log.sh
chmod +x /home/sunline/apps/uploadphotoservice/logs/auto-del-15-days-ago-log.sh
3、编辑脚本
cd /home/sunline/apps/calcservice/logs/
vi auto-del-15-days-ago-log.sh
#!/bin/sh
find /home/sunline/apps/calcservice/logs -mtime +15 -name "sys_poll.log.*" -exec rm -rf {} \;
find /home/sunline/apps/calcservice/logs -mtime +15 -name "sys_plugin.log.*" -exec rm -rf {} \;
find /home/sunline/apps/calcservice/logs -mtime +15 -name "sys_onl_links.log.*" -exec rm -rf {} \;
find /home/sunline/apps/calcservice/logs -mtime +15 -name "sys_onl_busi.log.*" -exec rm -rf {} \;
find /home/sunline/apps/calcservice/logs -mtime +15 -name "sys_default.log.*" -exec rm -rf {} \;
find /home/sunline/apps/calcservice/logs -mtime +15 -name "sys_boot.log.*" -exec rm -rf {} \;
:wq(保存退出)
4、将auto-del-15-days-ago-log.sh执行脚本加入到系统计划任务,到点自动执行
crontab -e
// 后端需要在8个服务中都加一遍
10 0 15 * * /home/sunline/apps/calcservice/logs/auto-del-15-days-ago-log.sh >/dev/null 2>&1
10 0 15 * * /home/sunline/apps/docprintservice/logs/auto-del-15-days-ago-log.sh >/dev/null 2>&1
10 0 15 * * /home/sunline/apps/loginservice/logs/auto-del-15-days-ago-log.sh >/dev/null 2>&1
10 0 15 * * /home/sunline/apps/payservice/logs/auto-del-15-days-ago-log.sh >/dev/null 2>&1
10 0 15 * * /home/sunline/apps/saveservice/logs/auto-del-15-days-ago-log.sh >/dev/null 2>&1
10 0 15 * * /home/sunline/apps/searchservice/logs/auto-del-15-days-ago-log.sh >/dev/null 2>&1
10 0 15 * * /home/sunline/apps/underwriteservice/logs/auto-del-15-days-ago-log.sh >/dev/null 2>&1
10 0 15 * * /home/sunline/apps/uploadphotoservice/logs/auto-del-15-days-ago-log.sh >/dev/null 2>&1
5、查看有哪些定时任务
crontab -l