当提示输入用户凭据而不是指定变量 ($user) 时,Expect 正在发送 $expect_out(buffer)。然后超时。下面是代码:
...
}
"yes" {
send_user "\nEnter your username for the WLC supporting the new APs:\n"
sleep 6
}
}
expect {
-re "(.*)\n" {
set user $expect_out(1,string)
}
}
send_user "\nEnter your password for the WLC supporting the new APs:\n"
sleep 15
expect {
-re "(.*)\n" {
set pass $expect_out(1,string)
}
}
sleep 1
send_user "\nSshing to the IP of the WLC supporting the new APs ($wlc_temp)\n"
spawn ssh $wlc_temp
expect {
"User:" {
send $user\n
sleep 1
}
}
expect {
"assword:" {
send $pass\n
sleep 1
}
}
结果如下:
(设备主机名)用户:(设备主机名)用户:
以下是调试:
SSH 到支持新 AP () 的无线控制器的 IP
期望:“”(spawn_id exp6)是否匹配全局模式“用户:”?不
期望:“\r\n”(spawn_id exp6)是否匹配全局模式“用户:”?否(设备主机名)用户:
期望:“\r\n(设备主机名)用户:”(spawn_id exp6)是否匹配全局模式“用户:”?是期望:设置期望输出(0,字符串)“用户:”期望:设置期望输出(spawn_id)“exp6”期望:设置期望输出(缓冲区)“\r\n(设备主机名)用户:”发送:发送“\n”到 { exp6 }
期望:“”(spawn_id exp6)是否匹配全局模式“assword:”?不
(设备主机名)用户:
期望:“\r\n(设备主机名)用户:”(spawn_id exp6)是否匹配全局模式“assword:”?没有期望:超时
更新: 将请求用户输入的语句重新定位到脚本的顶部是一种解决方法。