{"id":2602,"date":"2023-05-15T12:31:23","date_gmt":"2023-05-15T03:31:23","guid":{"rendered":"https:\/\/weblog.hirohiro716.com\/?p=2602"},"modified":"2024-09-19T15:01:22","modified_gmt":"2024-09-19T06:01:22","slug":"bash%e3%81%ae%e5%bf%98%e3%82%8c%e3%81%8c%e3%81%a1%e3%81%aa%e6%96%87%e6%b3%95","status":"publish","type":"post","link":"https:\/\/weblog.hirohiro716.com\/?p=2602","title":{"rendered":"Bash\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8\u306e\u5fd8\u308c\u304c\u3061\u306a\u66f8\u304d\u65b9"},"content":{"rendered":"<p>\n\u65e5\u4ed8\u5f62\u5f0f\u306e\u6587\u5b57\u5217\u3092\u4f7f\u7528\u3059\u308b\u3002\n<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n#!\/bin\/bash\r\n# &quot;2023-05-15 12:31:22&quot; \u3092\u8868\u793a\r\ntest1=$(date +&quot;%Y-%m-%d %H:%M:%S&quot;)\r\necho $test1\r\n# &quot;20230505&quot; \u3092\u8868\u793a\r\ntest2=$(date --date &quot;-10 days&quot; +&quot;%Y%m%d&quot;)\r\necho $test2\r\n<\/pre>\n<p style=\"margin-top:2em;\">\n\u30b3\u30de\u30f3\u30c9\u306e\u6210\u529f\u3068\u5931\u6557\u3092\u5224\u5b9a\u3059\u308b\u3002\n<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n#!\/bin\/bash\r\ndirectoryLocation=&quot;\/tmp\/directory\/&quot;\r\nmkdir $directoryLocation\r\nif &#x5B; ! $? -eq 0 ]; then\r\n    echo &quot;\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u4f5c\u6210\u306b\u5931\u6557\u3057\u307e\u3057\u305f\u3002&quot;\r\nfi\r\n<\/pre>\n<p style=\"margin-top:2em;\">\n\u30d5\u30a1\u30a4\u30eb\u3084\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u5b58\u5728\u3092\u78ba\u8a8d\u3059\u308b\u3002\n<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n#!\/bin\/bash\r\ndirectoryLocation=&quot;\/tmp\/directory\/&quot;\r\nif &#x5B; ! -d &quot;$directoryLocation&quot; ]; then\r\n    echo &quot;\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306f\u5b58\u5728\u3057\u307e\u305b\u3093\u3002&quot;\r\nfi\r\nfileLocation=&quot;${directoryLocation}test.txt&quot;\r\nif &#x5B; ! -f &quot;$fileLocation&quot; ]; then\r\n    echo &quot;\u30d5\u30a1\u30a4\u30eb\u306f\u5b58\u5728\u3057\u307e\u305b\u3093\u3002&quot;\r\nfi\r\nanyItemLocation=&quot;\/tmp\/any-item&quot;\r\nif &#x5B; -e &quot;$anyItemLocation&quot; ]; then\r\n    echo &quot;\u4f55\u304b\u304c\u5b58\u5728\u3057\u307e\u3059\u3002&quot;\r\nfi\r\n<\/pre>\n<p style=\"margin-top:2em;\">\n\u3088\u304fcron\u3067\u6570\u79d2\u3054\u3068\u306b\u51e6\u7406\u3057\u305f\u3044\u5834\u5408\u306b\u4f7f\u7528\u3059\u308b\u3002\u975e\u540c\u671f\u3067\u306e\u5b9f\u884c\u306b\u306a\u308b\u3002\n<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n#!\/bin\/bash\r\nfor i in `seq 0 5 59`; do \r\n    (\r\n        sleep $i\r\n        echo &quot;$i Running&quot;\r\n    ) &amp;\r\ndone;\r\n<\/pre>\n<p style=\"margin-top:2em;\">\n\u3053\u3061\u3089\u3082cron\u3067\u591a\u7528\u3059\u308b\u3002\u5b9f\u884c\u6642\u306e\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u5f15\u6570\u3082\u542b\u3081\u305f\u30d7\u30ed\u30bb\u30b9\u3092\u78ba\u8a8d\u3057\u3066\u3001\u5b9f\u884c\u4e2d\u306e\u30d7\u30ed\u30bb\u30b9\u304c\u306a\u3051\u308c\u3070\u65b0\u3057\u3044\u30d7\u30ed\u30bb\u30b9\u3092\u8d77\u52d5\u3059\u308b\u3088\u3046\u306a\u5834\u5408\u306b\u4f7f\u7528\u3059\u308b\u3002<br \/>\n\u203bx\u30aa\u30d7\u30b7\u30e7\u30f3\u306f\u5236\u5fa1tty\u3092\u6301\u305f\u306a\u3044\u30d7\u30ed\u30bb\u30b9\u3092\u8868\u793a<br \/>\n\u203ba\u30aa\u30d7\u30b7\u30e7\u30f3\u306ftty\u3092\u6301\u3064\u3059\u3079\u3066\u306e\u30d7\u30ed\u30bb\u30b9\u3092\u8868\u793a\n<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n#!\/bin\/bash\r\nsec=&quot;123&quot;\r\ntest=$(ps xa 2&gt;\/dev\/null | grep $sec 2&gt;\/dev\/null)\r\nif &#x5B;&#x5B; ! $test = *&quot;top -d $sec&quot;* ]]; then\r\n    top -d $sec\r\nfi\r\n<\/pre>\n<p style=\"margin-top:2em;\">\n\u8d77\u52d5\u30b3\u30de\u30f3\u30c9\u306b\u90e8\u5206\u4e00\u81f4\u3057\u305f\u30d7\u30ed\u30bb\u30b9\u3092kill\u3057\u305f\u3044\u5834\u5408\u306b\u4f7f\u7528\u3059\u308b\u3002<br \/>\n\u203b\u30d7\u30ed\u30bb\u30b9\u540d\u304c&#8221;next-server (v14.2.8)&#8221;\u3060\u3063\u305f\u5834\u5408\u306e\u4f8b<br \/>\n\u203b-o\u30aa\u30d7\u30b7\u30e7\u30f3\u306f\u8868\u793a\u9805\u76ee\u3092\u6307\u5b9a\n<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n#!\/bin\/bash\r\nprocess=$(ps xa -o pid,command | grep next | grep server);\r\nfor pid in $process\r\ndo\r\n    kill $pid\r\n    break\r\ndone\r\n<\/pre>\n<p style=\"margin-top:2em;\">\n\u7279\u5b9a\u306e\u30ea\u30c3\u30b9\u30f3\u30dd\u30fc\u30c8\u306b\u4e00\u81f4\u3059\u308b\u30d7\u30ed\u30bb\u30b9\u3092kill\u3057\u305f\u3044\u5834\u5408\u306b\u4f7f\u7528\u3059\u308b\u3002<br \/>\n\u203b-l\u30aa\u30d7\u30b7\u30e7\u30f3\u306f\u30ea\u30c3\u30b9\u30f3\u72b6\u614b\u306e\u30bd\u30b1\u30c3\u30c8\u3060\u3051\u3092\u8868\u793a<br \/>\n\u203b-n\u30aa\u30d7\u30b7\u30e7\u30f3\u306f\u30b5\u30fc\u30d3\u30b9\u540d\u3067\u306f\u306a\u304f\u30dd\u30fc\u30c8\u756a\u53f7\u3092\u8868\u793a<br \/>\n\u203b-p\u30aa\u30d7\u30b7\u30e7\u30f3\u306f\u30d7\u30ed\u30bb\u30b9\u306e\u60c5\u5831\u3092\u8868\u793a\n<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n#!\/bin\/bash\r\nport=3000\r\nprocesses=$(ss -lnp | grep $port)\r\nprocesses=(${processes\/\/,\/ })\r\nfor part in ${processes&#x5B;@]}\r\ndo\r\n    if &#x5B;&#x5B; $part == &quot;pid=&quot;* ]]; then\r\n        pid=$(echo $part | sed &quot;s\/pid=\/\/g&quot;)\r\n        kill $pid\r\n        break\r\n    fi\r\ndone\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u65e5\u4ed8\u5f62\u5f0f\u306e\u6587\u5b57\u5217\u3092\u4f7f\u7528\u3059\u308b\u3002 #!\/bin\/bash # &quot;2023-05-15 12:31:22&quot; \u3092\u8868\u793a test1=$(date +&quot;%Y-%m-%d %H:%M:%S&quot;)  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-2602","post","type-post","status-publish","format-standard","hentry","category-linux"],"views":643,"_links":{"self":[{"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=\/wp\/v2\/posts\/2602","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2602"}],"version-history":[{"count":12,"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=\/wp\/v2\/posts\/2602\/revisions"}],"predecessor-version":[{"id":2849,"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=\/wp\/v2\/posts\/2602\/revisions\/2849"}],"wp:attachment":[{"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2602"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2602"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2602"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}