LoginSignup
14
13

More than 5 years have passed since last update.

peco + ssh + 社内API + jq = 対話型sshで仕事が捗った

Last updated at Posted at 2014-12-26

社内にホスト名一覧をjsonで返すAPIがあったので、jqとpecoで対話的にホスト名を選択してログインできるようにした。

.bashrc

.bashrc
function list_intra_hosts() {
  # 社内APIが返すjsonの"name" キーがホスト名
  # jqでホスト名のみをリスト化
  curl -sS http://apihost/hosts | jq -r '.[] | .name'
}

function ssh_intra_host() {
  ssh $(list_hosts | peco)
}

alias pssh=ssh_intra_host

使い方

$ pssh

まとめ

社内APIと連携して対話的にホストにログインすることができた。

個人的にpecoなどを社内のオペレーションの仕組みに取り入れる発想があまりなかったので、ちょっとしたライフジェインジングなハックだった。

14
13
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
14
13