我的脚本ssh进入了HP交换机,并对接口进行了更改。我不知道是什么导致了输出中的错误字符(参见粗体)。
我的剧本:
#!/usr/bin/expect
spawn ssh -o StrictHostKeyChecking=no user@switch
expect {
"password:" { send "passwd\r" ; exp_continue }
"Press any key to continue" { send " \r" ; exp_continue }
"240#" { send "conf t\r" }
}
expect {
"(config)#" { send "int 8\r" }
}
expect {
"(eth-8)#" { send "enable\r" }
}
expect {
"(eth-8)#" { send "wr mem\r" }
}
expect {
"(eth-8)#" { send "end\r" }
}
expect {
"#" { send "logout\r" }
}
expect eof见下面的错误输出:;209 R&;209 R^C
user@user-site:/config/scripts$ ./test_disable.exp
spawn ssh -o StrictHostKeyChecking=no user@switch
========= WARNING: Unauthorized access to this system is forbidden
and will be prosecuted by law. By accessing this system, you agree
that your actions may be monitored if unauthorized usage is suspected.
===
user@switch's password:
Press any key to continue
Your previous successful login (as user) was on 2016-11-18 14:30:54
from <ip removed>
swtch-16-57-240#
swtch-16-57-240# conf t
swtch-16-57-240(config)# int 8;209R
swtch-16-57-240(eth-8)# enable
swtch-16-57-240(eth-8)# wr mem
swtch-16-57-240(eth-8)# end
swtch-16-57-240# logout
Do you want to log out [y/n]? y
Connection to switch closed by remote host.
Connection to switch closed.
user@user-site:/config/scripts$ ;209R^C
user@user-site:/config/scripts$发布于 2016-11-18 21:59:49
会不会是一个被咀嚼的控制序列?唯一以R结尾的vt100序列是:
Cursor position report CPR ESC [ Pl ; Pc R其中Pl和Pc是光标位置的行号和列号的整数(参见http://www.vt100.net/docs/vt102-ug/appendixc.html)。
简单的解决方案可能是运行ssh,例如:
set env(TERM) dumb
spawn env TERM=dumb ssh -o StrictHostKeyChecking=no user@switch更难的方法是从某种程度上剥去逃逸序列。还可以尝试将dumb更改为vt100 (它当前设置为什么?)
https://stackoverflow.com/questions/40686347
复制相似问题