「expect」に基づいて異なるパスワード文字列を送信するexpectスクリプトを作成しようとしています
条件A:Ciscoデバイスにユーザー名が設定されていない場合、最初のプロンプトは単に「Password:」になります。次に、passwordA(ユーザー名なし)を使用する必要があります。
条件B:ユーザー名で設定されている場合、プロンプトは「ユーザー名:」に続いて「パスワード:」になります-ユーザー名とパスワードBを使用する必要があります
#!/bin/bash
# Declare host variable as the input variable
host=$1
# Start the expect script
(expect -c "
set timeout 20
# Start the session with the input variable and the rest of the hostname
spawn telnet $host
set timeout 3
if {expect \"Password:\"} {
send \"PasswordA\"}
elseif { expect \"Username:\"}
send \"UsersName\r\"}
expect \"Password:\"
log_user 0
send \"PasswordB\r\"
log_user 1
expect \"*>\"
# send \"show version\r\"
# set results $expect_out(buffer)
#expect \"Password:\"
#send \"SomeEnablePassword\r\"
# Allow us to interact with the switch ourselves
# stop the expect script once the telnet session is closed
send \"quit\r\"
expect eof
")