DRYな備忘録

Don't Repeat Yourself.

curlのレスポンスをgrepしたものを1秒おきにwatchしたい

watchしたい出力

  • localhost:9200で動くAPI
  • curlのprogress出力は要らないので-sして
  • レスポンスの中の"management"という文言から後ろ7行
curl :9200/_nodes/stats/thread_pool?pretty -s\
| grep -A7 \"management\"

に対する

        "management" : {
          "threads" : 2,
          "queue" : 0,
          "active" : 1,
          "rejected" : 0,
          "largest" : 2,
          "completed" : 1358
        },

これを1秒ごとに見たい

動かんやつ

  • curl :9200/_nodes/stats/thread_pool?pertty=1 | grep -A7 \"management\"

watchつける前から動かない。MacOSXだとcurlでportからはじめてもlocalhostで補完してくれるんだけど、DebianCentOSだと

% curl :80
curl: (6) Couldn't resolve host ''

ってなるので、ちゃんとlocalhost:9200とする。http://は補完されてる模様。


  • watch -n1 curl localhost:9200/_nodes/stats/thread_pool?pretty -s | grep -A7 \"management\"

watchコマンドは、正しくはwatch "実行したいコマンド"であって、今回はgrepまでが実行したいコマンドに相当するので、そこまでをクオートで囲む必要がある。

serverfault.com

動いたやつ

  • watch -n1 "curl localhost:9200/_nodes/stats/thread_pool?pretty -s | grep -A7 \"management\""

参考

cURL - How To Use