{"id":390,"date":"2019-05-29T10:07:40","date_gmt":"2019-05-29T01:07:40","guid":{"rendered":"http:\/\/localhost:8000\/?p=390"},"modified":"2021-01-23T12:31:42","modified_gmt":"2021-01-23T03:31:42","slug":"linux-bash-memo","status":"publish","type":"post","link":"http:\/\/localhost:8000\/2019\/05\/linux-bash-memo.html","title":{"rendered":"\u305f\u307e\u306b\u4f7f\u3046Linux\u30b3\u30de\u30f3\u30c9\u3084bash\u30b9\u30af\u30ea\u30d7\u30c8\u30e1\u30e2"},"content":{"rendered":"
\u305f\u307e\u306b\u4f7f\u3046Linux\u30b3\u30de\u30f3\u30c9\u3084\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u968f\u6642\u30e1\u30e2\u3057\u3066\u3044\u304f\u4e88\u5b9a\u3067\u3059\u3002<\/p>\n
\u3068\u3066\u3082\u51e6\u7406\u6642\u9593\u304c\u304b\u304b\u308b\u51e6\u7406\u3092\u5b9f\u884c\u3059\u308b\u969b\u306b\u3001\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u304c\u5207\u308c\u305f\u308a\u3057\u3066\u51e6\u7406\u304c\u505c\u6b62\u3059\u308b\u306e\u3092\u907f\u3051\u305f\u3044\u3068\u304d\u306b\u4f7f\u3044\u307e\u3059\u3002<\/p>\n
# nohup\u3067hangup\u30b7\u30b0\u30ca\u30eb\u3092\u7121\u8996\u3057\u3001\u30d0\u30c3\u30af\u30b0\u30e9\u30a6\u30f3\u30c9\u3067\u5b9f\u884c\u3055\u305b\u308b\nnohup \u30b3\u30de\u30f3\u30c9 &\nnohup pg_dump -h localhost -p 5432 -U admin -Fc -f hoge.dmp hoge &\n\n# \u30b8\u30e7\u30d6\u306e\u78ba\u8a8d\u30fb\u505c\u6b62\u30fb\u518d\u958b\u306a\u3069\u306f\u901a\u5e38\u3068\u540c\u3058<\/code><\/pre>\n\u30d0\u30c3\u30af\u30b0\u30e9\u30a6\u30f3\u30c9\u5b9f\u884c\u3001\u30d5\u30a9\u30a2\u30b0\u30e9\u30a6\u30f3\u30c9\u5b9f\u884c<\/h2>\n# \u30d0\u30c3\u30af\u30b0\u30e9\u30a6\u30f3\u30c9\u3067\u5b9f\u884c\u3059\u308b\n\u30b3\u30de\u30f3\u30c9 &\nsar 5 555 &\n> [2] 9095\n> Linux 5.4.0-1025-gcp (stg-scraper01) 2020\u5e7410\u670801\u65e5 _x86_64_ (2 CPU)\n\n# \u5b9f\u884c\u4e2d\u306e\u30b8\u30e7\u30d6\u3092\u30d0\u30c3\u30af\u30b0\u30e9\u30a6\u30f3\u30c9\u306b\u79fb\u52d5\uff08\u3053\u306e\u6642\u70b9\u3067\u306f\u505c\u6b62\u72b6\u614b\u306b\u306a\u308b\uff09\nsar 5 555\nctlr + z\n> [1]+ Stopped sar 5 555\n\n# \u505c\u6b62\u4e2d\u306e\u30b8\u30e7\u30d6\u3092\u30d0\u30c3\u30af\u30b0\u30e9\u30a6\u30f3\u30c9\u3067\u5b9f\u884c\u3059\u308b\nbg %1\n> [1]+ sar 5 555 &\n\n# \u30b8\u30e7\u30d6\u3092\u30d5\u30a9\u30a2\u30b0\u30e9\u30a6\u30f3\u30c9\u306b\u79fb\u52d5\nfg %1\n> sar 5 555\n\n# \u30b8\u30e7\u30d6\u3092\u78ba\u8a8d\u3059\u308b\njobs\n> [1]+ Running sar 5 555 &\n\n# \u30b8\u30e7\u30d6\u3092\u505c\u6b62\u3059\u308b\nkill %1\nkill -KILL %1<\/code><\/pre>\n\u30b0\u30ed\u30fc\u30d0\u30ebIP\u30a2\u30c9\u30ec\u30b9\u3092\u53d6\u5f97<\/h2>\nifconfig en0 | grep inet | grep -v inet6 | sed -E "s\/inet ([0-9]{1,3}.[0-9]{1,3}.[0-9].{1,3}.[0-9]{1,3}) .*$\/\\1\/" | tr -d "\\t"\n\n# \u51fa\u529b\u7d50\u679c\n11.22.33.44<\/code><\/pre>\n\u7279\u5b9a\u306e\u30dd\u30fc\u30c8\u3092\u4f7f\u3063\u3066\u3044\u308b\u30d7\u30ed\u30bb\u30b9\u3092\u78ba\u8a8d\u3059\u308b<\/h2>\nlsof -i:8080\n\n# \u51fa\u529b\u7d50\u679c\nCOMMAND PID USER FD TYPE DEVICE SIZE\/OFF NODE NAME\ncom.docke 123 hoge 26u IPv4 0xc120a5f57fb38b6b 0t0 TCP *:http (LISTEN)<\/code><\/pre>\n\u7279\u5b9a\u306e\u30db\u30b9\u30c8\u306e\u7279\u5b9a\u306e\u30dd\u30fc\u30c8\u304c\u7a7a\u3044\u3066\u308b\u304b\u3069\u3046\u304b\u3092\u78ba\u8a8d\u3059\u308b<\/h2>\ntelnet {\u30db\u30b9\u30c8\u540d} {\u30dd\u30fc\u30c8\u756a\u53f7}\ntelnet hoge_host 5432\n\n# \u51fa\u529b\u7d50\u679c\uff08\u3053\u306e\u7d50\u679c\u304c\u8fd4\u3063\u3066\u304d\u305f\u3089OK\uff09\nTrying 11.22.33.44...\nConnected to hoge_host.\nEscape character is '^]'.<\/code><\/pre>\n\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u7d4c\u8def\u3092\u78ba\u8a8d\u3059\u308b<\/h2>\ntraceroute -d google.com\n# -d \u5f97\u3089\u308c\u305f\u7d4c\u8def\u9014\u4e2d\u306eIP\u306b\u3064\u3044\u3066\u3001DNS\u306e\u9006\u5f15\u304d\u3092\u3057\u306a\u3044\u306e\u3067\u9ad8\u901f\n# -I windows\u7248\u306etracert\u3068\u540c\u3058\u304f\u3001ICMP Echo Request\u3092\u7528\u3044\u308b\uff08 FW\u306e\u8a2d\u5b9a\u3067\u3053\u3061\u3089\u3060\u3051\u7a74\u304c\u7a7a\u3044\u3066\u308b\u5834\u5408\u306a\u3069\u306f\u3053\u3063\u3061\u3092\u4f7f\u3063\u3066\u307f\u308b\uff09\n\n# \u51fa\u529b\u7d50\u679c\ntraceroute to google.com (216.58.197.174), 64 hops max, 52 byte packets\n 1 192.168.0.1 (192.168.0.1) 2.305 ms 2.632 ms 2.423 ms\n 2 xxx1.asahi-net.or.jp (124.155.80.1) 4.616 ms 6.747 ms 5.942 ms\n 3 xxx2.asahi-net.or.jp (124.155.80.2) 5.057 ms 4.968 ms 5.707 ms\n 4 xxx3.asahi-net.or.jp (124.155.80.3) 4.133 ms 4.804 ms 4.447 ms\n 5 xxx4.asahi-net.or.jp (202.224.51.4) 7.835 ms 6.161 ms 6.117 ms\n 6 xxx5.asahi-net.or.jp (202.224.51.5) 6.219 ms 8.218 ms 11.443 ms\n 7 ebgp-google2.asahi-net.or.jp (202.224.35.93) 11.065 ms 6.074 ms 6.128 ms\n 8 108.170.242.129 (108.170.242.129) 7.782 ms\n 108.170.242.97 (108.170.242.97) 8.412 ms 5.692 ms\n 9 216.239.62.27 (216.239.62.27) 5.975 ms 5.651 ms\n 216.239.62.29 (216.239.62.29) 5.803 ms\n10 nrt12s02-in-f14.1e100.net (216.58.197.174) 6.008 ms 5.727 ms 7.425 ms<\/code><\/pre>\nSCP\u3067\u30d5\u30a1\u30a4\u30eb\u8ee2\u9001<\/h2>\n# \u30d5\u30a1\u30a4\u30eb\u3092\u9001\u4fe1\u3059\u308b\nscp <\u30d5\u30a1\u30a4\u30eb\u30d1\u30b9> <\u30b5\u30fc\u30d0\u540d>:<\u30d5\u30a9\u30eb\u30c0\u30d1\u30b9>\nscp test.txt hoge_server:\/tmp\/\n\n# \u30d5\u30a1\u30a4\u30eb\u3092\u53d7\u4fe1\u3059\u308b\nscp <\u30b5\u30fc\u30d0\u540d>:<\u30d5\u30a1\u30a4\u30eb\u30d1\u30b9> <\u30d5\u30a9\u30eb\u30c0\u30d1\u30b9>\nscp hoge_server:\/tmp\/test.txt \/tmp\/\n<\/code><\/pre>\n\u30c7\u30a3\u30b9\u30af\u5bb9\u91cf\u78ba\u8a8d<\/h2>\n# \u30d5\u30a1\u30a4\u30eb\u30b7\u30b9\u30c6\u30e0\u306e\u4f7f\u7528\u72b6\u6cc1\u3092\u78ba\u8a8d\u3059\u308b\ndf -h\n # -h human readable\n\n# \u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u5225\u306e\u4f7f\u7528\u91cf\u3092\u78ba\u8a8d\u3059\u308b\ndu -ch\n # -c total\u3092\u51fa\u529b\n # -h human readable<\/code><\/pre>\n\u30e6\u30fc\u30b6\u3092\u4f5c\u6210\u3059\u308b\uff06\u524a\u9664\u3059\u308b<\/h2>\n# \u4f5c\u6210\n# -m home\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3082\u4f5c\u308b\n# -s \u8d77\u52d5\u30b7\u30a7\u30eb\u3092\u6307\u5b9a\u3059\u308b\nuseradd -m -s '\/bin\/bash' {\u540d\u524d}\n\n# \u524a\u9664\n# -r home\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u524a\u9664\u3059\u308b\nuserdel -r {\u540d\u524d}\n<\/code><\/pre>\nsudo \u6a29\u9650\u306e\u8a2d\u5b9a<\/h2>\n
\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067sudoers\u30d5\u30a1\u30a4\u30eb\u306e\u7de8\u96c6\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n
sudo visudo<\/code><\/pre>\nsudoers\u30d5\u30a1\u30a4\u30eb\u3067\u306f\u3001\u4ee5\u4e0b\u306e\u5f62\u5f0f\u3067\u8a31\u53ef\u3059\u308b\u6a29\u9650\u3092\u8a18\u8f09\u3057\u307e\u3059\u3002<\/p>\n
# \u8ab0\u304c \u3069\u306e\u30db\u30b9\u30c8\u3067=(\u8ab0\u3068\u3057\u3066) \u4f55\u3092\u3059\u308b\n# \u4f8b1) root\u30e6\u30fc\u30b6\u304c\u3001\u5168\u3066\u306e\u30db\u30b9\u30c8\u3067\u3001\u5168\u3066\u306e\u30e6\u30fc\u30b6\u3068\u3057\u3066\u3001\u5168\u3066\u3092\u3059\u308b\u3053\u3068\u3092\u8a31\u53ef\nroot ALL=(ALL) ALL\n# \u4f8b2) hoge\u30e6\u30fc\u30b6\u304c\u3001\u5168\u3066\u306e\u30db\u30b9\u30c8\u3067\u3001fuga\u30e6\u30fc\u30b6\u3068\u3057\u3066\u3001git clone\u3092\u3059\u308b\u3053\u3068\u3092\u8a31\u53ef\nhoge ALL=(fuga) \/usr\/bin\/git clone *\n# \u4f8b3) hoge\u30e6\u30fc\u30b6\u304c\u3001\u5168\u3066\u306e\u30db\u30b9\u30c8\u3067\u3001fuga\u30e6\u30fc\u30b6\u3068\u3057\u3066\u3001\u30d1\u30b9\u30ef\u30fc\u30c9\u306a\u3057\u3066git clone\u3092\u3059\u308b\u3053\u3068\u3092\u8a31\u53ef\nhoge ALL=(fuga) NOPASSWD: \/usr\/bin\/git clone *\n# \u4f8b4) hoge\u30e6\u30fc\u30b6\u304c\u3001\u5168\u3066\u306e\u30db\u30b9\u30c8\u3067\u3001fuga\u30e6\u30fc\u30b6\u3068\u3057\u3066\u3001\u74b0\u5883\u5909\u6570\u3092\u5f15\u304d\u7d99\u3044\u3067\u3001bash\u3092\u5b9f\u884c\u3059\u308b\u3053\u3068\u3092\u8a31\u53ef\n# \u3000\u5229\u7528\u4f8b) sudo -Eu fuga sh -c ". env\/bin\/activate && python main.py"\nhoge ALL=(fuga) SETENV: \/bin\/sh *<\/code><\/pre>\n\u30b0\u30eb\u30fc\u30d7\u6307\u5b9a\u3001\u30ab\u30f3\u30de\u3067\u30b3\u30de\u30f3\u30c9\u8907\u6570\u5217\u6319\u3001\u30ef\u30a4\u30eb\u30c9\u30ab\u30fc\u30c9\u306b\u3064\u3044\u3066\u306a\u3069\u3001\u8a73\u7d30\u306f\u4ee5\u4e0b\u306e\u30d6\u30ed\u30b0\u304c\u3068\u3066\u3082\u308f\u304b\u308a\u3084\u3059\u3044\u306e\u3067\u53c2\u7167\u3055\u305b\u3066\u3044\u305f\u3060\u304d\u307e\u3059\u3002
\nhttps:\/\/qiita.com\/progrhyme\/items\/6f936033b9d23efb1741<\/a><\/p>\nssh keys\u306e\u4f5c\u6210<\/h2>\nssh-keygen -t rsa<\/code><\/pre>\nbash\u3067\u4e8c\u6b21\u5143\u914d\u5217<\/h2>\nreadonly array=(\n "hoge1 fuga1"\n "hoge2 fuga2"\n "hoge3 fuga3"\n)\n\nfor row in "${array[@]}"; do\n echo ${row}\ndone\n> hoge1 fuga1\n> hoge2 fuga2\n> hoge3 fuga3\n\nfor row in "${array[@]}"; do\n data=(${row[@]})\n echo ${data[0]}\n echo ${data[1]}\ndone\n> hoge1\n> fuga1\n> hoge2\n> fuga2\n> hoge3\n> fuga3\n<\/code><\/pre>\n\u30ea\u30bd\u30fc\u30b9\u78ba\u8a8d<\/h2>\n## \u30e1\u30e2\u30ea\u78ba\u8a8d\uff08free\u30b3\u30de\u30f3\u30c9\uff09\nfree -ht\n# -h human readable\n# -t Mem + Swap\u306e\u5408\u8a08\u3092\u51fa\u529b\n> total used free shared buff\/cache available\n> Mem: 25G 15G 9G 276K 196M 9.9G\n> Swap: 2.0G 1.9G 91M\n> Total: 27G 17G 10G\n\n## \u5b9f\u884c\u4e2d\u30d7\u30ed\u30bb\u30b9\u78ba\u8a8d\uff08top\u30b3\u30de\u30f3\u30c9\uff09\ntop\n# \u8d77\u52d5\u4e2d\u306b\u4ee5\u4e0b\u306e\u30ad\u30fc\u3092\u30bf\u30a4\u30d7\u3059\u308b\u3053\u3068\u3067\u8868\u793a\u3092\u5207\u308a\u66ff\u3048\u3089\u308c\u308b\n # h: \u30d8\u30eb\u30d7\u8868\u793a\n # c: command\u3092full path\u306b\u3059\u308b\u304b\u3069\u3046\u304b\n # M: %MEM\u3067\u30bd\u30fc\u30c8\uff08\u30c7\u30d5\u30a9\u30eb\u30c8\u306f%CPU\u3067\u30bd\u30fc\u30c8\u3055\u308c\u3066\u3044\u308b\uff09\n # m: \u30e1\u30e2\u30ea\u306e\u8868\u793a\u5207\u308a\u66ff\u3048\n # P: %CPU\u3067\u30bd\u30fc\u30c8\n # t: CPU\u306e\u8868\u793a\u5207\u308a\u66ff\u3048\n # 1: CPU\u72b6\u6cc1\u3092CPU\u5225\u306b\u8868\u793a\n # R: \u30bd\u30fc\u30c8\u9806\u3092\u9006\u306b\u3059\u308b\n # u: \u6307\u5b9a\u3057\u305f\u30e6\u30fc\u30b6\u3067filter\u30ea\u30f3\u30b0\n # A: \u30e1\u30a4\u30f3\u30a6\u30a3\u30f3\u30c9\u30a6\u3001PID\u30a6\u30a3\u30f3\u30c9\u30a6\n # F: \u30d5\u30a3\u30fc\u30eb\u30c9\u4e00\u89a7\u8868\u793a\u3002\u4e0a\u4e0b\u3067\u79fb\u52d5\u3057\u3066\u30b9\u30da\u30fc\u30b9\u3067\u9078\u629e\u3067\u304d\u308b\n> top - 16:58:22 up 4:37, 1 user, load average: 1.45, 1.35, 1.19\n> Tasks: 145 total, 3 running, 87 sleeping, 0 stopped, 0 zombie\n> %Cpu(s): 50.0 us, 0.0 sy, 0.0 ni, 49.5 id, 0.0 wa, 0.0 hi, 0.4 si, 0.0 st\n> KiB Mem : 26747548 total, 6776520 free, 18885016 used, 1086012 buff\/cache\n> KiB Swap: 2097148 total, 2097148 free, 0 used. 7507508 avail Mem\n> \n> PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND\n> 28606 hoge 20 0 14.852g 0.014t 36892 R 100.0 56.2 7:23.15 python\n> 7357 hoge 20 0 3439648 869472 44460 R 65.3 3.3 51:17.60 python\n> 2043 fuga 20 0 10.235g 2.859g 31108 S 2.0 11.2 5:31.34 java\n> 7 root 20 0 0 0 0 S 0.3 0.0 0:00.13 ksoftirqd\/0\n> 15086 hoge 20 0 40288 3872 3132 R 0.3 0.0 0:00.11 top\n> 1 root 20 0 225412 9216 6744 S 0.0 0.0 0:02.02 systemd<\/code><\/pre>\n\u8ad6\u7406CPU\u30b3\u30a2\u6570\u78ba\u8a8d<\/h2>\ngrep processor \/proc\/cpuinfo | wc -l<\/code><\/pre>\ntail -f \u306e\u4ee3\u308f\u308a\u306bless +F \u3092\u4f7f\u3046<\/h2>\nless hoge_fuga.log\n\nF : \u5927\u6587\u5b57F\u3067tail\u30e2\u30fc\u30c9\u306b\nctrl + C: \u901a\u5e38\u30e2\u30fc\u30c9\u306b<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"\u305f\u307e\u306b\u4f7f\u3046Linux\u30b3\u30de\u30f3\u30c9\u3084\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u968f\u6642\u30e1\u30e2\u3057\u3066\u3044\u304f\u4e88\u5b9a\u3067\u3059\u3002 \u30bf\u30fc\u30df\u30ca\u30eb\u304b\u3089\u30ed\u30b0\u30a2\u30a6\u30c8\u3057\u3066\u3082\u30b3\u30de\u30f3\u30c9\u3092\u52d5\u304b\u3057\u7d9a\u3051\u308b \u3068\u3066\u3082\u51e6\u7406\u6642\u9593\u304c\u304b\u304b\u308b\u51e6\u7406\u3092\u5b9f\u884c\u3059\u308b\u969b\u306b\u3001\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u304c\u5207\u308c\u305f\u308a\u3057\u3066\u51e6\u7406\u304c\u505c\u6b62\u3059\u308b\u306e\u3092\u907f\u3051\u305f\u3044\u3068\u304d\u306b\u4f7f\u3044\u307e\u3059\u3002 # nohup\u3067hangup\u30b7\u30b0\u30ca\u30eb\u3092\u7121\u8996\u3057\u3001\u30d0\u30c3\u30af\u30b0\u30e9\u30a6\u30f3\u30c9\u3067\u5b9f\u884c\u3055\u305b\u308b nohup \u30b3\u30de\u30f3\u30c9 & nohup pg_dump -h localhost -p 5432 -U admin -Fc -f hoge.dmp hoge & # \u30b8\u30e7\u30d6\u306e\u78ba\u8a8d\u30fb\u505c\u6b62\u30fb\u518d\u958b\u306a\u3069\u306f\u901a\u5e38\u3068\u540c\u3058 \u30d0\u30c3\u30af\u30b0\u30e9\u30a6\u30f3\u30c9\u5b9f\u884c\u3001\u30d5\u30a9\u30a2\u30b0\u30e9\u30a6\u30f3\u30c9\u5b9f\u884c # \u30d0\u30c3\u30af\u30b0\u30e9\u30a6\u30f3\u30c9\u3067\u5b9f\u884c\u3059\u308b \u30b3\u30de\u30f3\u30c9 & sar 5 555 & > [2] 9095 > Linux 5.4.0-1025-gcp (stg-scraper01) 2020\u5e7410\u670801\u65e5 _x86_6 <\/span>Continue Reading<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[34],"tags":[],"_links":{"self":[{"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/posts\/390"}],"collection":[{"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/comments?post=390"}],"version-history":[{"count":1,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/posts\/390\/revisions"}],"predecessor-version":[{"id":391,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/posts\/390\/revisions\/391"}],"wp:attachment":[{"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/media?parent=390"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/categories?post=390"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/tags?post=390"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}