Linuxマシンがログイン後にパスワードを要求すると、次のexpectスクリプトがうまく動作します。しかし、私たちのLinuxマシンの中には、SSHのパスワードを必要としないものがあります(私たちはパスワードなしでログインできます)ので、パスワードなしのマシンをサポートするためにexpectスクリプトを変更する必要があります。どうやってやるの?パスワードを必要としないマシンでexpectベースのSSHスクリプトが動作するように変更する
$ expect_test=`cat << EOF
set timeout -1
spawn ssh $IP hostname
expect {
")?" { send "yes\r" ; exp_continue }
word: {send "pass123\r" }
}
expect eof
EOF`
$ expect -c "$expect_test"
パスワードを必要とするマシン上で実行されている:パスワードを必要としないマシン上で実行している場合
$ IP=10.17.18.6
$ expect -c "$expect_test"
spawn ssh 10.17.18.6 hostname
sh: /usr/local/bin/stty: not found
This computer system, including all related equipment, networks and network devices (specifically including Internet access),is pros
yes
Password:
Linux1_machine
:あなたからタイムアウト
$ IP=10.10.92.26
$ expect -c "$expect_test"
spawn ssh 10.10.92.26 hostname
sh: /usr/local/bin/stty: not found
Linux15_machine
expect: spawn id exp5 not open
while executing
"expect eof"
パスワードは一度だけ送信することにします。幸いにも、それは少し余分なロジックで実行するのは簡単です。 –
すばらしい答えがうまくいった –