{"id":124,"date":"2020-06-18T09:00:28","date_gmt":"2020-06-18T01:00:28","guid":{"rendered":"https:\/\/22pig.com\/?p=124"},"modified":"2020-06-18T09:00:28","modified_gmt":"2020-06-18T01:00:28","slug":"cutnginxlog-sh-nginx-%e6%97%a5%e5%bf%97%e6%96%87%e4%bb%b6%e5%88%87%e5%89%b2%e5%92%8c%e5%ae%9a%e6%97%b6%e6%89%a7%e8%a1%8c","status":"publish","type":"post","link":"http:\/\/22pig.com\/?p=124","title":{"rendered":"cutnginxlog.sh  -Nginx \u65e5\u5fd7\u6587\u4ef6\u5207\u5272\u548c\u5b9a\u65f6\u6267\u884c \u622a\u53d6 \u622a\u65ad"},"content":{"rendered":"<p>#!\/bin\/sh<br \/>\n# Program:<br \/>\n# Auto cut nginx log script.<\/p>\n<p># nginx\u65e5\u5fd7\u8def\u5f84<br \/>\nLOGS_PATH=\/usr\/local\/nginx\/logs<br \/>\nTODAY=$(date -d &#8216;today&#8217; +%Y-%m-%d)<\/p>\n<p># \u79fb\u52a8\u65e5\u5fd7\u5e76\u6539\u540d<br \/>\nmv ${LOGS_PATH}\/error.log ${LOGS_PATH}\/error_${TODAY}.log<br \/>\nmv ${LOGS_PATH}\/access.log ${LOGS_PATH}\/access_${TODAY}.log<br \/>\n#zip -m ${LOGS_PATH}\/error_${TODAY}.log.zip ${LOGS_PATH}\/error_${TODAY}.log<br \/>\n#zip -m ${LOGS_PATH}\/access_${TODAY}.log.zip ${LOGS_PATH}\/access_${TODAY}.log<br \/>\ntar -czf ${LOGS_PATH}\/error_${TODAY}.log.tar.gz ${LOGS_PATH}\/error_${TODAY}.log &#8211;remove-files<br \/>\ntar -czf ${LOGS_PATH}\/access_${TODAY}.log.tar.gz ${LOGS_PATH}\/access_${TODAY}.log &#8211;remove-files<\/p>\n<p># \u5411nginx\u4e3b\u8fdb\u7a0b\u53d1\u9001\u91cd\u65b0\u6253\u5f00\u65e5\u5fd7\u6587\u4ef6\u7684\u4fe1\u53f7<br \/>\nkill -USR1 $(cat \/usr\/local\/nginx\/logs\/nginx.pid)<\/p>\n<p>#echo &#8216;0 0 * * * root \/usr\/local\/nginx\/cutnginxlog.sh &gt;&gt; \/usr\/local\/nginx\/logs\/cutnginxlog.log 2&gt;&amp;1&#8217; &gt;&gt; \/etc\/crontab<\/p>\n<p>#crontab -e<\/p>\n","protected":false},"excerpt":{"rendered":"<p>#!\/bin\/sh # Program: # Auto cut nginx log script. # nginx\u65e5\u5fd7\u8def\u5f84 LOGS_PATH=\/usr\/local\/nginx\/logs TODAY=$(date -d &#8216;today&#8217; +%Y-%m-%d) # \u79fb\u52a8\u65e5\u5fd7\u5e76\u6539\u540d mv ${LOGS_PATH}\/error.log ${LOGS_PATH}\/error_${TODAY}.log mv ${LOGS_PATH}\/access.log ${LOGS_PATH}\/access_${TODAY}.log #zip -m ${LOGS_PATH}\/error_${TODAY}.log.zip ${LOGS_PATH}\/error_${TODAY}.log #zip -m ${LOGS_PATH}\/access_${TODAY}.log.zip ${LOGS_PATH}\/access_${TODAY}.log tar -czf ${LOGS_PATH}\/error_${TODAY}.log.tar.gz ${LOGS_PATH}\/error_${TODAY}.log &#8211;remove-files tar -czf ${LOGS_PATH}\/access_${TODAY}.log.tar.gz ${LOGS_PATH}\/access_${TODAY}.log &#8211;remove-files # \u5411nginx\u4e3b\u8fdb\u7a0b\u53d1\u9001\u91cd\u65b0\u6253\u5f00\u65e5\u5fd7\u6587\u4ef6\u7684\u4fe1\u53f7 kill -USR1 $(cat \/usr\/local\/nginx\/logs\/nginx.pid) #echo &#8216;0 0 * * * root [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-124","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"http:\/\/22pig.com\/index.php?rest_route=\/wp\/v2\/posts\/124","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/22pig.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/22pig.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/22pig.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/22pig.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=124"}],"version-history":[{"count":0,"href":"http:\/\/22pig.com\/index.php?rest_route=\/wp\/v2\/posts\/124\/revisions"}],"wp:attachment":[{"href":"http:\/\/22pig.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=124"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/22pig.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=124"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/22pig.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=124"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}