2つの部分で構成されるssh +ポート転送コマンドを生成する私が本当に好きなスクリプトがあります。
ssh -N -f -o 'ControlMaster Auto' -o 'ControlPath /tmp/gimme_access' -o 'ControlPersist 1m' -L 6473:33.22.0.0:22 -i /home/sink/.ssh/id_dsa -o 'UserKnownHostsFile /home/sink/.ssh/known_hosts' -p 6000 [email protected] ; ssh -p 6473 -l noc -i /home/my_boy/.ssh/id_rsa -o 'StrictHostKeyChecking no' 127.0.0.1
これにより、これらのコンピュータにログインするために書き換えることができるさまざまなデバイスに公開されていますが、接続文字列のみを出力するコマンドが優先されます。
上記の文字列を生成してログイン状態を維持するコマンドをパイプできることはありますか?私は強打するためにパイピングしようとしましたが、すぐに終了しました。
ベストアンサー1
これを使用して、eval
文字列に格納されている(または他のプログラムの出力に基づいて)コマンドを実行できます。
eval 'echo Hello World'
eval $(magic-ssh-commmand-generator)
からman bash
:
eval [arg ...]
The args are read and concatenated together into a single command.
This command is then read and executed by the shell, and its exit status
is returned as the value of eval. If there are no args, or only null
arguments, eval returns 0.