{"id":7843,"date":"2019-06-14T10:40:44","date_gmt":"2019-06-14T02:40:44","guid":{"rendered":"http:\/\/rmohan.com\/?p=7843"},"modified":"2019-06-14T10:40:46","modified_gmt":"2019-06-14T02:40:46","slug":"tomcat-log-automatic-deletion-implementation","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=7843","title":{"rendered":"Tomcat log automatic deletion implementation"},"content":{"rendered":"\n<p>Tomcat log automatic deletion implementation<\/p>\n\n\n\n<p>ackground<\/p>\n\n\n\n<p>In the production environment, Tomcat generates a lot of logs every day. If you don&#8217;t clean up the disk capacity, it will be enough. Manual cleaning is too much trouble. Therefore, write a script to delete the log files 5 days ago (depending on the actual situation).<\/p>\n\n\n\n<p>Writing a script<\/p>\n\n\n\n<ol><li>Write a \/usr\/local\/script\/cleanTomcatlog.sh script <\/li><\/ol>\n\n\n\n<h1 class=\"wp-block-heading\">!\/bin\/bash<\/h1>\n\n\n\n<p>export WEB_TOMCAT1=\/usr\/local\/tomcat1\/logs<br>\nexport WEB_TOMCAT2=\/usr\/local\/tomcat2\/logs<br>\nexport WEB_TOMCAT3=\/usr\/local\/tomcat3\/logs<br>\necho &gt; ${WEB_TOMCAT1}\/catalina.out<br>\necho &gt; ${WEB_TOMCAT2}\/catalina.out<br>\necho &gt; ${WEB_TOMCAT3}\/catalina.out<br>\nfind ${WEB_TOMCAT1}\/* -mtime +5 -type f -exec rm -f {} \\;<br>\nfind ${WEB_TOMCAT2}\/* -mtime +5 -type f -exec rm -f {} \\;<br>\nfind ${WEB_TOMCAT3}\/* -mtime +5 -type f -exec rm -f {} \\;<\/p>\n\n\n\n<ol><li>Set the cleanTomcatlog.sh script to execute <br>\nchmod a+x cleanTomcatlog.sh<\/li><li>Enter the following command <br>\ncrontab -e on the console<\/li><li>Press i to edit this text file, enter the following, restart tomcat every day at 4:30 am<\/li><\/ol>\n\n\n\n<p>Press esc to exit editing, enter wq and enter to save <br>\n  30 04 * * * \/usr\/local\/script\/cleanTomcatlog.sh<\/p>\n\n\n\n<p>Press esc to exit editing, enter wq and enter to save.<\/p>\n\n\n\n<p>The restart timer task <br>\n<\/p>\n\n\n<p>[the root @]<\/p>\n\n\n\n<p> # the crond STOP-Service [the root @] # the crond Start-Service\n<\/p>\n\n\n\n<p>Name explanation<\/p>\n\n\n\n<p>Explain the crontab and find commands<\/p>\n\n\n\n<p>Crontab <br>\ncan set the execution schedule of the program through crontab, for example, let the program execute at 8 o&#8217;clock every day, or every 10 o&#8217;clock on Monday. <br>\ncrontab -l lists the schedule; <br>\ncrontab -e to edit schedule; <br>\ncrontab -d deletion schedule; &#8220;the -l&#8221; nothing to say, is a view of it; &#8220;-e&#8221; is the editor, <\/p>\n\n\n\n<p>and vi no difference (in fact, vi is editing a specific file); &#8220;-d&#8221; basic need, because it put all the user&#8217;s schedule are removed, usually do not put a timetable for progressive deleted with &#8220;-e&#8221; editor; that How to edit it? crontab file format is: MHD md CMD. A 6 field, the last CMD is the program to be executed, such as cleanTomcatlog.sh. M: minute (0-59) H: hour (0-23) D: date (1-31) m: month (1-12) d: one day of the week (0-6, 0 for Sunday) these five fields separated by a space of time which can be a digital value, may be a plurality of numbers separated by commas (or other), if there were not set, <\/p>\n\n\n\n<p>the default is &#8220;*.&#8221; For example, every day 04 points 30 points execution cleanTomcatlog.sh, is == 30 04 * * * \/usr\/local\/script\/cleanTomcatlog.sh==.<\/p>\n","protected":false},"excerpt":{"rendered":"\n<p>Tomcat log automatic deletion implementation<\/p>\n<p>ackground<\/p>\n<p>In the production environment, Tomcat generates a lot of logs every day. If you don&#8217;t clean up the disk capacity, it will be enough. Manual cleaning is too much trouble. Therefore, write a script to delete the log files 5 days ago (depending on the actual situation).<\/p>\n<p>Writing [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7843"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7843"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7843\/revisions"}],"predecessor-version":[{"id":7844,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7843\/revisions\/7844"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7843"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7843"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7843"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}