LoginSignup
0
1

[bash]ワンライナーで、コマンドの結果を検索パターンとしてgrepする(プロセス置換)

Last updated at Posted at 2023-12-25

背景(やりたかったこと)

毎障害時に、MySQLのProcessListにAWS EMRのインスタンスからのIPが存在しているかどうかを調べる(謎)手順がありました。
しかし、一覧取得して1つずつgrepしている現状の手順に嫌気がさしてきたので、ワンライナーでの実現方法を調べました。

結論

mysql -h${hostname} -u${username} -p${password} -e "select * from information_schema.processlist;"|grep -f <(aws emr list-instances --cluster-id ${cluster id} --instance-states RUNNING|jq -r '.PrivateIpAddress')

取得順序

1. ProcessList取得方法

mysqlコマンドで以下のようにselectする

mysql -h${hostname} -u${username} -p${password} -e "select * from information_schema.processlist;"

2. EMRのインスタンスをIP一覧を取得する

awd cliで取得可能

aws emr list-instances --cluster-id ${cluster id} --instance-states RUNNING|jq -r '.PrivateIpAddress'

2で取得した一覧をgrepの検索パターンとする

プロセス置換 + grep -fで実現可能

grep -f

これはプロセス置換という機能で実現できているらしい

以上より、結論のコマンドができあがりました。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1