{"id":1459,"date":"2022-04-02T11:51:49","date_gmt":"2022-04-02T03:51:49","guid":{"rendered":"http:\/\/blog.ywdevops.cn\/?p=1459"},"modified":"2024-03-01T12:10:14","modified_gmt":"2024-03-01T04:10:14","slug":"shell-5","status":"publish","type":"post","link":"https:\/\/blog.ywdevops.cn\/index.php\/2022\/04\/02\/shell-5\/","title":{"rendered":"shell\u51fd\u6570"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Linux shell\u4e5f\u652f\u6301\u51fd\u6570\uff0c\u4f46\u662f\u51fd\u6570\u7684\u9000\u51fa\u72b6\u6001\u503c\u53ea\u80fd\u662f0\u6216\u80051\uff0c\u5982\u679c\u811a\u672c\u4e2d\u6709\u91cd\u590d\u4ee3\u7801\u7684\u65f6\u5019\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u51fd\u6570\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u51fd\u6570\u540d\u524d\u9762\u53ef\u4ee5\u52a0\u4e0a\u5173\u952e\u5b57function,\u4f46\u662f\u52a0\u4e0e\u4e0d\u52a0\u5bf9\u51fd\u6570\u7684\u6267\u884c\u6ca1\u6709\u5f71\u54cd\uff0c\u51fd\u6570\u4e2d\u81f3\u5c11\u6709\u4e00\u6761\u547d\u4ee4\uff0c\u4e0d\u5141\u8bb8\u7a7a\u547d\u4ee4\u5b58\u5728\uff0c\u51fd\u6570\u4e4b\u95f4\u901a\u8fc7\u53c2\u6570\u3001\u51fd\u6570\u8fd4\u56de\u503c\u8fdb\u884c\u901a\u4fe1\uff0c\u51fd\u6570\u5728\u811a\u672c\u4e2d\u51fa\u73b0\u7684\u6b21\u5e8f\u53ef\u4ee5\u4f7f\u4efb\u610f\u7684\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f8b\u5982\uff0c\u65b0\u5efa\u4e00\u4e2a\u811a\u672c\uff0c\u51fd\u6570\u540d\u4e3ahello\uff0c\u5e76\u8c03\u7528\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"597\" height=\"217\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2020\/05\/20-2.png\" alt=\"\" class=\"wp-image-1460\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2020\/05\/20-2.png 597w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2020\/05\/20-2-300x109.png 300w\" sizes=\"auto, (max-width: 597px) 100vw, 597px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u56fe\u662f\u4e00\u4e2a\u5faa\u73af\u8c03\u7528\u51fd\u6570\u7684\u4f8b\u5b50\uff0c\u7ed3\u679c\u4e3a\u6253\u53704\u884c12345\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"418\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2020\/05\/23-3.png\" alt=\"\" class=\"wp-image-1465\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2020\/05\/23-3.png 600w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2020\/05\/23-3-300x209.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u5224\u65ad\u5f53\u524d\u76ee\u5f55\u4e0b\u5b58\u5728\u591a\u5c11\u4e2a\u6587\u4ef6\u4ee5\u53ca\u5b50\u76ee\u5f55\uff0c\u6267\u884c\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"593\" height=\"488\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2020\/05\/14-2.png\" alt=\"\" class=\"wp-image-1467\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2020\/05\/14-2.png 593w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2020\/05\/14-2-300x247.png 300w\" sizes=\"auto, (max-width: 593px) 100vw, 593px\" \/><\/figure>\n\n\n\n<p class=\"has-luminous-vivid-amber-background-color has-background wp-block-paragraph\">\u6ce8\u610f\uff1a\u51fd\u6570\u8c03\u7528\u662f\u8ddf\u51fd\u6570\u4f4d\u7f6e\u76f8\u5173\u7684\uff0c\u51fd\u6570\u8981\u5728\u811a\u672c\u7684\u4e0a\u65b9\uff0c\u4e0b\u65b9\u5185\u5bb9\u8c03\u7528\u51fd\u6570\uff0c\u5982\u679c\u5c06\u51fd\u6570\u653e\u5728\u4e0b\u9762\uff0c\u5728\u4e0a\u65b9\u8c03\u7528\u4f1a\u62a5\u9519<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u4f8b\u5b50\u4e3a\u6e05\u7406elk\u7d22\u5f15\u7684\u4f8b\u5b50\uff0c\u901a\u8fc7case\u7ed3\u6784\u548c\u51fd\u6570\u4ee5\u53cafor\u5faa\u73af\u5b9e\u73b0\uff0c\u51fd\u6570\u5728\u4e0a\u65b9\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n: '\n @function: clean elk log\n @author: gongguan\n @date: 2022-04-01\n @\u8bf4\u660e: \u672c\u4f8b\u5b50\u4e2d\u53ea\u5199\u51fa\u4e862022\u5e74\u7684\uff0c\u540e\u7eed\u53ef\u4ee5\u7ee7\u7eed\u6269\u5c55\u52302023\u30012024\u5e74\u7b49\uff0c\u6e05\u7406\u65f6\u5019\u6839\u636e\u63d0\u793a\u8f93\u5165\u5e74\u4efd\n \u548c\u6708\u4efd\u5373\u53ef\n @\u6ce8\u610f\uff1a\u51fd\u6570\u8981\u5728\u811a\u672c\u5185\u5bb9\u4e0a\u65b9\uff0c\u5426\u5219\u8c03\u7528\u4f1a\u62a5\u9519\n'\ncleanLog(){\n  for i in $(curl 'localhost:9200\/_cat\/indices?v' | awk '{print $3}')\n  do\n    result=$(echo $i | grep ''${month}'')\n    if &#91; -n \"${result}\" ];then\n      curl -XDELETE http:\/\/localhost:9200\/${result}\n    fi\n\n  done\n}\nread -p \"\u8bf7\u8f93\u5165\u8981\u6e05\u695a\u7684\u5e74\u4efd(2022\/2023):\" year\ncase $year in\n2022)\n  read -p \"\u8bf7\u8f93\u5165\u8981\u6e05\u9664\u7684\u6708\u4efd(01\/02\/03....):\" month\n  case $month in\n  01)\n   cleanLog\n   ;;\n  02)\n   cleanLog\n   ;;\n   03)\n   cleanLog\n   ;;\n   04)\n   cleanLog\n   ;;\n   05)\n   cleanLog\n   ;;\n    06)\n   cleanLog\n   ;;\n   07)\n   cleanLog\n   ;;\n   08)\n   cleanLog\n   ;;\n   09)\n   cleanLog\n   ;;\n   10)\n   cleanLog\n   ;;\n   01)\n   cleanLog\n   ;;\n   12)\n   cleanLog\n   ;;\n   *)\n    echo \"\u8f93\u5165\u7684\u6708\u4efd\u4e0d\u5339\u914d\"  \n  esac\n;;\n*)\n  echo \"\u5e74\u4efd\u4e0d\u5339\u914d\uff0c\u8bf7\u91cd\u65b0\u8f93\u5165.....\"\n;;\nesac\n<\/code><\/pre>\n\n\n\n<p class=\"has-text-align-center wp-block-paragraph\"><strong>\u5411\u51fd\u6570\u4f20\u9012\u53c2\u6570<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728shell\u7f16\u7a0b\u4e2d\uff0c\u5411\u51fd\u6570\u4f20\u9012\u53c2\u6570\u8fd8\u662f\u901a\u8fc7\u4f4d\u7f6e\u53c2\u6570\u7684\u65b9\u5f0f\uff0c\u4e0d\u652f\u6301\u4f20\u6570\u7ec4<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1\u3001\u5411\u811a\u672c\u4e2d\u4f20\u9012\u5355\u4e2a\u53c2\u6570\uff0c\u5e76\u6267\u884c\u8c03\u7528\u51fd\u6570\uff0c\u67e5\u770b\u7ed3\u679c\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"597\" height=\"278\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2020\/05\/15-2.png\" alt=\"\" class=\"wp-image-1468\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2020\/05\/15-2.png 597w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2020\/05\/15-2-300x140.png 300w\" sizes=\"auto, (max-width: 597px) 100vw, 597px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u9996\u5148\u53c2\u657010\u8d4b\u503c\u7ed9m\uff0c\u4e0b\u65b9\u8c03\u7528\u51fd\u6570\u7684\u65f6\u5019\uff0cm\u7684\u503c\u4f20\u9012\u5230\u51fd\u6570\u4e2d\u7ed9n\uff0cn\u7684\u503c\u8fdb\u884c\u51cf\u534a\uff0c\u4ece\u6267\u884c\u7ed3\u679c\u53ef\u4ee5\u770b\u51fa\uff0cm\u7684\u503c\u5e76\u6ca1\u6709\u53d1\u751f\u53d8\u5316\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"596\" height=\"196\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2020\/05\/16-2.png\" alt=\"\" class=\"wp-image-1469\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2020\/05\/16-2.png 596w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2020\/05\/16-2-300x99.png 300w\" sizes=\"auto, (max-width: 596px) 100vw, 596px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">2\u3001\u5411\u51fd\u6570\u4f20\u9012\u591a\u4e2a\u53c2\u6570\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"694\" height=\"160\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/03\/10.jpg\" alt=\"\" class=\"wp-image-16227\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/03\/10.jpg 694w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/03\/10-300x69.jpg 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/03\/10-600x138.jpg 600w\" sizes=\"auto, (max-width: 694px) 100vw, 694px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"694\" height=\"78\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/03\/11.jpg\" alt=\"\" class=\"wp-image-16228\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/03\/11.jpg 694w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/03\/11-300x34.jpg 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/03\/11-600x67.jpg 600w\" sizes=\"auto, (max-width: 694px) 100vw, 694px\" \/><\/figure>\n\n\n\n<p class=\"has-text-align-center wp-block-paragraph\"><strong>\u51fd\u6570\u7684\u8fd4\u56de\u503c<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6709\u65f6\u5019\u811a\u672c\u6267\u884c\u5b8c\u6210\u540e\u9700\u8981\u8fd4\u56de\u7279\u5b9a\u7684\u503c\u6765\u5b8c\u6210\u811a\u672c\u7684\u540e\u9700\u52a8\u4f5c\uff0c\u8fd9\u4e9b\u7279\u5b9a\u7684\u503c\u5c31\u662f\u51fd\u6570\u7684\u8fd4\u56de\u503c\uff0cshell\u7f16\u7a0b\u4e2d\uff0c\u901a\u8fc7return\u6765\u8868\u793a\u9000\u51fa\u72b6\u6001\uff0c0\u8868\u793a\u65e0\u9519\u8bef\uff0c1\u8868\u793a\u6709\u9519\u8bef<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f8b\u5982\uff1a\u6839\u636e\u8fd4\u56de\u503c\u7684\u4e0d\u540c\u6765\u8f93\u51fa\u4e0d\u540c\u7684\u7ed3\u679c\uff0c\u5982\u679c\u51fd\u6570\u8fd4\u56de0\u5219\u6253\u5370\u6b63\u786e\uff0c\u8fd4\u56de1\u5219\u6253\u5370\u9519\u8bef\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"601\" height=\"510\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2020\/05\/17-2.png\" alt=\"\" class=\"wp-image-1471\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2020\/05\/17-2.png 601w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2020\/05\/17-2-300x255.png 300w\" sizes=\"auto, (max-width: 601px) 100vw, 601px\" \/><\/figure>\n\n\n\n<p class=\"has-text-align-center wp-block-paragraph\"><strong>\u51fd\u6570\u7684\u8c03\u7528<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">shell\u811a\u672c\u4e2d\u53ef\u4ee5\u653e\u7f6e\u591a\u4e2a\u884c\u6570\uff0c\u51fd\u6570\u4e4b\u95f4\u53ef\u4ee5\u76f8\u4e92\u8c03\u7528\uff0c\u4e00\u4e2a\u51fd\u6570\u53ef\u4ee5\u8c03\u7528\u591a\u4e2a\u51fd\u6570\uff0c\u811a\u672c\u4e2d\u5982\u679c\u653e\u7f6e\u591a\u4e2a\u51fd\u6570\uff0c\u6267\u884c\u7684\u65f6\u5019\u5c06\u6309\u7167\u8c03\u7528\u51fd\u6570\u7684\u987a\u5e8f\u8fdb\u884c\u6267\u884c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f8b\u5982\uff0c\u5728\u811a\u672c\u4e2d\u5199\u5165\u591a\u4e2a\u51fd\u6570\uff0c\u5e76\u8fdb\u884c\u8c03\u7528\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"601\" height=\"504\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2020\/05\/18-2.png\" alt=\"\" class=\"wp-image-1472\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2020\/05\/18-2.png 601w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2020\/05\/18-2-300x252.png 300w\" sizes=\"auto, (max-width: 601px) 100vw, 601px\" \/><\/figure>\n\n\n\n<p class=\"has-text-align-center wp-block-paragraph\"><strong>\u51fd\u6570\u76f8\u4e92\u8c03\u7528<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u51fd\u6570\u4e4b\u95f4\u53ef\u4ee5\u76f8\u4e92\u8c03\u7528\uff0c\u8c03\u7528\u65f6\u4f1a\u505c\u6b62\u8fd0\u884c\u5f53\u524d\u51fd\u6570\u8f6c\u53bb\u8fd0\u884c\u88ab\u8c03\u7528\u7684\u51fd\u6570\uff0c\u8c03\u7528\u5b8c\u6210\u540e\u518d\u56de\u6765\u8fd0\u884c\u5f53\u524d\u7684\u51fd\u6570\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f8b\u5982\uff1a\u6709\u4e09\u4e2a\u51fd\u6570\uff0c\u6700\u540e\u4e00\u4e2a\u51fd\u6570\u4e3a\u8c03\u7528\u51fd\u6570\uff0c\u6839\u636e\u8f93\u5165\u4e0d\u540c\u7684\u503c\u8c03\u7528\u4e0d\u540c\u7684\u51fd\u6570\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"597\" height=\"523\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2020\/05\/19-2.png\" alt=\"\" class=\"wp-image-1473\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2020\/05\/19-2.png 597w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2020\/05\/19-2-300x263.png 300w\" sizes=\"auto, (max-width: 597px) 100vw, 597px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Linux shell\u4e5f\u652f\u6301\u51fd\u6570\uff0c\u4f46\u662f\u51fd\u6570\u7684\u9000\u51fa\u72b6\u6001\u503c\u53ea\u80fd\u662f0\u6216\u80051\uff0c\u5982\u679c\u811a\u672c\u4e2d\u6709\u91cd\u590d\u4ee3\u7801\u7684\u65f6\u5019\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528 [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":7951,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34,37],"tags":[],"class_list":["post-1459","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","category-shell"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":8}},"_links":{"self":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/1459","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1459"}],"version-history":[{"count":9,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/1459\/revisions"}],"predecessor-version":[{"id":16229,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/1459\/revisions\/16229"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media\/7951"}],"wp:attachment":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1459"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1459"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1459"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}