最初のパスワードが失敗した後、別のパスワードを返すことができるようにする必要があります。これは、プロンプトが同じ期待値「Password:」を要求する 2 回目になります。
(expect -c "
#exp_internal 1
set passwords {PASS1 PASS2}
set index 0
set timeout 20
# Start the session with the input variable and the rest of the hostname
spawn telnet $host
set timeout 3
expect {
-ex \"Password:\" {
send \"[lindex $passwords $index]\r\"
incr index
exp_continue;
}
}
私はそれを機能させることができません。lindex
送信には何もないようです:
-ex "Password:" {
send "[lindex ]\r"