TCL Expect在登录提示时发送$Expect_(缓冲区)
当提示输入用户凭据而不是指定变量($user)时,Expect正在发送$Expect_(缓冲区)。然后超时。代码如下:TCL Expect在登录提示时发送$Expect_(缓冲区),tcl,expect,Tcl,Expect,当提示输入用户凭据而不是指定变量($user)时,Expect正在发送$Expect_(缓冲区)。然后超时。代码如下: ... } "yes" { send_user "\nEnter your username for the WLC supporting the new APs:\n" sleep 6 } } expect { -re "(.*)\n" {
...
}
"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
}
}
结果如下:
(设备主机名)用户:(设备主机名)
用户:
以下是调试:
Sshing到支持新AP的WLC的IP()
繁殖ssh
父级:正在等待同步字节
家长:告诉孩子继续
父:现在与子繁殖不同步:返回{7153}
预期:“(spawn_id exp6)是否与全局模式”用户:“?没有
预期:“\r\n”(生成id exp6)是否与全局模式“用户:”匹配?不
(设备主机名)用户:
预期:“\r\n(设备主机名)用户:”
(生成id exp6)匹配全局模式“用户:”?对
expect:set expect\u out(0,字符串)“用户:”expect:set expect\u out(spawn\u id)“exp6”
expect:设置expect\u out(缓冲区)“\r\n(设备主机名)用户:”
发送:将“\n”发送到{exp6}
expect:“(spawn_id exp6)是否匹配全局模式”assword:?没有
(设备主机名)用户:
预期:“\r\n(设备主机名)用户:”(生成id exp6)是否与全局匹配
模式“assword:”?不
预期:超时
更新:
将请求用户输入的语句重新定位到脚本顶部是一种解决方法。当您想从用户处读取输入时,应该使用
expect\u user
而不是expect
:
send_user "\nEnter your username for the WLC supporting the new APs:\n"
sleep 6
}
}
expect_user {
-re "(.*)\n" {
set user $expect_out(1,string)
}
}
send_user "\nEnter your password for the WLC supporting the new APs:\n"
sleep 15
expect_user {
-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"
# ...
(我还认为您可以在那里使用更少的
sleep
调用,而只是调整超时,但这不太可能对脚本的正确操作产生影响。)我做了您建议的更改,但仍然看到相同的行为。