文字列の後のカール出力をファイルに取り込む

文字列の後のカール出力をファイルに取り込む

bashスクリプトで "director-services"文字列の後のすべての内容をファイルに出力したいと思います。

$ curl localhost:9201/_cat/health
1472487809 12:23:29 director-services green 3 3 828 276 0 0 0 0

答え1

grepとの組み合わせを使用してくださいcut

$ curl ... | grep -o "director-services.*" | cut -d' ' -f2- 
green 3 3 828 276 0 0 0 0

または単にperl

$ curl ... |  perl -lne 'print $1 if /director-services (.*)/'
green 3 3 828 276 0 0 0 0

答え2

_catElasticSearchとAPIを使用してクラスタパラメータを照会するとします。

外部処理ツールは必要ありません。_catAPIには、クエリを使用するときにメタ文字を一致させることができるヘッダー一致機能があります?h=

列ヘッダーから始めてすべてを取得する必要があるため、次のものをnode.total使用できます。

_cat/health?h=node.total,*

例:

% curl 'localhost:9200/_cat/health'               
1472532922 00:55:22 foobar red 1 1 3279 3279 0 0 3190 0 - 50.7% 

% curl 'localhost:9200/_cat/health?v'
epoch      timestamp cluster status node.total node.data shards  pri relo init unassign pending_tasks max_task_wait_time active_shards_percent 
1472532925 00:55:25  foobar  red             1         1   3279 3279    0    0     3190             0                  -                 50.7% 

% curl 'localhost:9200/_cat/health?h=node.total,*'
1 1472532942 00:55:42 foobar red 1 3279 3279 0 0 3190 0 - 50.7% 

関連情報