{"id":131448,"date":"2019-01-04T09:00:55","date_gmt":"2019-01-04T01:00:55","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=131448"},"modified":"2018-12-28T14:00:35","modified_gmt":"2018-12-28T06:00:35","slug":"how-shell","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/how-shell.html","title":{"rendered":"\u600e\u4e48\u5f52\u6863\u8001\u65e5\u5fd7\u7684shell\u811a\u672c"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u672c\u811a\u672c\u6765\u81ea\u6709\u5b66\u4e60\u963f\u94ed\u7684\u535a\u6587\u5b66\u4e60\uff1a\u5de5\u4f5c\u4e2d\uff0c\u9700\u8981\u7528\u5230\u65e5\u5fd7\u5207\u5272logrotate\uff0c\u6309\u7167\u5404\u81ea\u7684\u9700\u8981\u5207\u5272\u3001\u5b9a\u4e49\u4fdd\u7559\u65e5\u5fd7\u3002\u63d0\u793a\uff1a\u672c\u6587\u4e2d\u7684S\u5168\u90e8\u90fd$\u7b26\uff0c\u4e0d\u8981\u95ee\u4e3a\u4ec0\u4e48\uff0c\u9a6c\u4e91\u7238\u7238\u7684\u793e\u533a\u5c31\u8fd9\u6837\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
#\u7528\u9014\uff1a\u65e5\u5fd7\u5207\u5272\u5f52\u6863\u3001\u6309\u5929\u5207\u5272\r\n#\u4f5c\u8005\uff1aCaron maktini\r\n#\u65e5\u671f\uff1a2018\u5e7412\u670815\u65e5\r\n#\u7248\u672c\uff1av0.1\r\n\r\nlogdir=\/data\/logs\/ \r\n#\u5b9a\u4e49\u51fd\u6570\u5982\u679c\u4e00\u4e2a\u6587\u4ef6\u5b58\u5728\u5219\u5220\u9664 \r\nfunction e_df()\r\n{\r\n    if [  -f $1  ]\r\n    then\r\n      rm -f  $1\r\n}\r\n\r\ncd  $logdir\r\n\r\n#\u4ece7\u52302\uff0c\u4f9d\u6b21\u904d\u5386\u5faa\u73af \r\nfor i in  `seq 7 -1 2`\r\ndo\r\n      #$i2\u6bd4Si\u5c0f1 \r\n      i2=$[Si-1]\r\n      \r\n      #\u9996\u5148\u5224\u65ad1.log.7\u662f\u5426\u5b58\u5728\uff0c\u82e5\u5b58\u5728\u5219\u5220\u9664 \r\n      e_df  1.log.$i\r\n    \r\n    #\u5f531.log.6\u5b58\u5728\uff0c\u5219\u628a1.log.6\u6539\u540d\u4e3a1.log.7,\u4f9d\u6b21\u7c7b\u63a8\r\n    if [  -f  1.log.$i2  ]\r\n    then\r\n        mv  1.log.$i2 1.log.$i\r\n    fi\r\ndone\r\n\r\n#\u7531\u4e8e1.log \u540e\u9762\u65e0\u540e\u7f00\uff0c\u6240\u4ee5\u4e0d\u80fd\u8d70\u4e0a\u9762\u7684for\u5faa\u73af\uff0c\u53ea\u80fd\u53e6\u5916\u62ff\u51fa\u6765\u5904\u7406\r\ne_df 1.log.1\r\nmv  1.log  1.log.1\r\n\r\n#\u6bcf\u65e50\u70b90\u5206\u6267\u884c\u3002<\/pre>\n

\u5de5\u4f5c\u4e2d\u8fd8\u9700\u8981\u4e3a\u5927\u6587\u4ef6\u8fdb\u884c\u5207\u5272\uff0c\u4e00\u822c\u5de5\u4f5c\u4e2d\u662f100MB\uff0c\u5e76\u8fdb\u884c\u538b\u7f29\u3002<\/p>\n

\u7b2c\u4e8c\u811a\u672c<\/p>\n

#!\/bin\/bash\r\n#\u7528\u9014\uff1a\u65e5\u5fd7\u5207\u5272\u5f52\u6863\u3001\u5e76\u538b\u7f29\r\n#\u4f5c\u8005\uff1aCaron maktini\r\n#\u65e5\u671f\uff1a2018\u5e7412\u670815\u65e5\r\n#\u7248\u672c\uff1av0.1\r\n\r\nlogdir=\/data\/logs\/ \r\n#\u6280\u672f1.log\u5927\u5c0f\r\nsize=`du -sk $logdir\/1.log | awk '{print S1}' \r\n\r\n#\u5982\u679c1.log\u5c0f\u4e8el00MB\uff0c\u5219\u9000\u51fa\u811a\u672c \r\n\r\nif [  $size -lt 10240 ] \r\nthen \r\n    exit 0\r\nfi \r\n\r\n#\u5b9a\u4e49\u51fd\u6570\uff0c\u5982\u679c\u4e00\u4e2a\u6587\u4ef6\u5b58\u5728\uff0c\u5219\u5220\u9664 \r\nfunction e_df()\r\n{\r\n    if   [  -f  $1 ]\r\n    then \r\n        rm -f $1 \r\n    fi \r\n}\r\n cd  $logdir\r\n\r\n#\u5982\u679c1.log.1\u5b58\u5728\uff0c\u5219\u5148\u628a\u5b83\u538b\u7f29\u4e3a1 log.1.gz\uff0c\u8fd9\u6837\u4e0b\u9762\u7684for\u5faa\u73af\u624d\u4e0d\u4f1a\u9519\r\n \r\nif   [ -f 1.log.1 ] \r\nthen \r\n    gzip 1.log.1 \r\nfi \r\n\r\n#\u7531\u4e8e1.log.1\u5df2\u7ecf\u88ab\u538b\u7f29\u4e3a1.log.gz\uff0c\u6240\u4ee5\u53ef\u4ee5\u76f4\u63a5\u5c061.log\u6539\u540d\u4e3a1.log.1\r\n\r\nmv  1.log  1.log.1\r\n\r\n#\u4ece7\u52302\uff0c\u5012\u5e8f\u5faa\u73af \r\nfor i in  `seq 7  -1 2 `\r\ndo \r\n     #$i2\u6bd4Si\u5c0f1\r\n    i2=$[Si-1]\r\n    \r\n    #\u9996\u5148\u5224\u65ad1 log.7.gz\u662f\u5426\u5b58\u5728\uff0c\u82e5\u5b58\u5728\u5220\u9664 \r\n    e_df  1.Iog. $i.gz\r\n \r\n    #\u5f531.log.6.gz\u5b58\u5728\uff0c\u5219\u628a1.log.6.gz\u6539\u540d\u4e3a1.log.7.gz\uff0c\u4ee5\u6b64\u7c7b\u63a8\r\n    if [ -f  1.Iog. $i2. gz ]\r\n    then \r\n         mv 1.Iog. $i2.gz  1.Iog.$i.gz \r\n    fi \r\ndone \r\n\r\n##\u8bf4\u660e:\u7531\u4e8e\u6211\u4eec\u9700\u8981\u6309\u7167\u65e5\u5fd7\u5927\u5c0f\u5207\u5272\uff0c\u6240\u4ee5\u8fd9\u4e2a\u811a\u672c\u5199\u5b8c\u540e\uff0c\u9700\u8981\u6bcf\u5206\u949f\u6267\u884c\u4e00\u6b21\uff0c\u5efa\u8bae\u6dfb\u52a0\u5230\u516c\u53f8\u7684\u76d1\u63a7\u7cfb\u7edf\u4e2d\u3002\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

#\u7528\u9014\uff1a\u65e5\u5fd7\u5207\u5272\u5f52\u6863\u3001\u6309\u5929\u5207\u5272 #\u4f5c\u8005\uff1aCaron maktini #\u65e5\u671f\uff1a2018\u5e7412\u670815\u65e5 #\u7248\u672c\uff1av […]<\/p>\n","protected":false},"author":63,"featured_media":132157,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-131448","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/131448","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/63"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=131448"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/131448\/revisions"}],"predecessor-version":[{"id":132182,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/131448\/revisions\/132182"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/132157"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=131448"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=131448"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=131448"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}