我正在尝试创建一个期望脚本,它将根据“期望”发送不同的密码字符串
条件 A:如果未使用用户名设置 cisco 设备,则第一个提示将只是“密码:” - 然后它应该使用密码 A(无用户名)
条件 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
")