{"id":150842,"date":"2019-07-17T08:19:08","date_gmt":"2019-07-17T00:19:08","guid":{"rendered":"https:\/\/gulass.cn\/?p=150842"},"modified":"2019-07-08T09:20:25","modified_gmt":"2019-07-08T01:20:25","slug":"shell-logs-gz","status":"publish","type":"post","link":"https:\/\/gulass.cn\/shell-logs-gz.html","title":{"rendered":"Shell\u81ea\u52a8\u5316\u538b\u7f29\u5904\u7406\u65e5\u5fd7\u6587\u4ef6\u811a\u672c\u7a0b\u5e8f"},"content":{"rendered":"
\u5bfc\u8bfb<\/td>\n | Shell\u5904\u7406\u65e5\u5fd7,\u81ea\u52a8\u4fdd\u755930\u5929\u7684\u65e5\u5fd7\uff0c\u5982\u679c\u8d85\u8fc714\u5929\u7684\u65e5\u5fd7\u5c31\u81ea\u52a8\u538b\u7f29\u4e3agz\u683c\u5f0f\u5b58\u50a8\u4e0b\u6765\uff0c\u8fd9\u6837\u53ef\u4ee5\u8282\u7701\u78c1\u76d8\u7a7a\u95f4\uff0c\u4e5f\u662f\u5b9a\u65f6\u5907\u4efd\u65e5\u5fd7\uff0c\u6211\u8fd9\u91cc\u662f\u4ee5\u65e5\u5fd7\u6587\u4ef6\u4e3e\u4f8b\u7684\uff0c\u5176\u5b83\u7684\u9700\u6c42\u4e5f\u53ef\u4ee5\u81ea\u5df1\u6839\u636e\u811a\u672c\u5185\u5bb9\u505a\u8c03\u6574\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n\r\n#!\/bin\/sh\r\n\r\n################################################################\r\n\r\n# (c) Copyright 2012 Eric. All rights reserved.\r\n\r\n#\r\n\r\n# Logs expired 30 days.\r\n\r\n#\r\n\r\n# *cron\r\n\r\n# 1 6 * * * \/bin\/sh \/var\/app\/shell\/logs_arrange.sh > \/var\/app\/shell\/cron_logs_arrange.log\r\n\r\n#\r\n\r\n#\r\n\r\n#\r\n\r\n################################################################\r\n\r\nTODAY=`date +%s`\r\n\r\n# how many days ago will the logs to be zip\r\n\r\nPK_DAYS_AGO=14\r\n\r\nPK_DATEDIFF=`expr ${PK_DAYS_AGO} \\* 86400`\r\n\r\nPK_EXT=gz\r\n\r\n# how many days ago will the logs to be removed\r\n\r\nDAYS_AGO=30\r\n\r\nDATEDIFF=`expr ${DAYS_AGO} \\* 86400`\r\n\r\ncleanDir(){\r\n\r\ndirectory=$1\r\n\r\nif [[ -d ${directory} ]];then\r\n\r\nfor file in `ls -1 ${directory} | grep -v '.log$'`;\r\n\r\ndo\r\n\r\nctime=`stat -c %Y ${directory}\/${file}`\r\n\r\ntimediff=`expr ${TODAY} - ${ctime}`\r\n\r\nextname=`ls ${directory}\/${file} | awk -F '.' '{printf $NF}'`\r\n\r\nif [[ ${extname} != ${PK_EXT} ]] ; then\r\n\r\nif [[ -f ${directory}\/${file} ]] ; then\r\n\r\nzipta=`expr ${timediff} - ${PK_DATEDIFF}`\r\n\r\nif [[ ${zipta} -gt 0 ]] ; then\r\n\r\necho \"Package ${directory}\/${file}\"\r\n\r\ngzip -f ${directory}\/${file} > ${directory}\/${file}.${PK_EXT}\r\n\r\nfi\r\n\r\nfi\r\n\r\nfi\r\n\r\nif [[ -f ${directory}\/${file} ]];then\r\n\r\ndelta=`expr ${timediff} - ${DATEDIFF}`\r\n\r\nif [[ ${delta} -gt 0 ]];then\r\n\r\necho \"Removing ${directory}\/${file}\"\r\n\r\nrm -rf ${directory}\/${file}\r\n\r\nfi\r\n\r\nfi\r\n\r\ndone\r\n\r\nfi\r\n\r\n}\r\n\r\ncleanDir \"\/var\/app\/logs\/webapps\/admin\"\r\n\r\ncleanDir \"\/var\/app\/logs\/webapps\/api\"\r\n\r\ncleanDir \"\/var\/app\/logs\/webapps\/pos\"\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":" |