tkuchikiの日記

新ブログ https://blog.tkuchiki.net

python

awscli の profile 名を補完できるようにする patch

aws-cli/1.7.29 用の patch です。Command Completion - AWS Command Line Interface を参考にコマンドを実行すると、 aws コマンドの補完ができるようになります。Configuring the AWS Command Line Interface - AWS Command Line Interface にあるように、…

ec2 instance の name tag と private ip を /etc/hosts に追記する

aws ec2 describe-instances が返す json を parse して、 /etc/hosts に private ip, name tag を追記するスクリプトです(name tag を hostname としてる場合を想定しています)。 aws configure をしている前提で書いていますが、 そうでない場合は、適宜 r…

python のワンライナーで、json の任意のキーの値を出力する

jq を使わないで行う方法です。 $ echo '{"hosts":[{"name":"host1"},{"name":"host2"}]}' | python -c "exec(\"import json,sys\\nj=json.load(sys.stdin)\\nfor attr in j.get('hosts'):\\n print attr.get('name')\")" host1 host2 python のコードに改行…