Bash expect脚本包含错误字符

Bash expect脚本包含错误字符,bash,tcl,expect,Bash,Tcl,Expect,我的脚本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_contin

我的脚本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
请参阅下面的错误输出: ;209R;209R^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$
user@user-站点:/config/scripts$。/test\u disable.exp
spawn ssh-o strichostkeychecking=nouser@switch
======警告:禁止未经授权访问此系统
并将被依法起诉。通过访问此系统,您同意
如果怀疑未经授权的使用,您的行为可能会受到监控。
===
user@switch的密码:
按任意键继续
您上一次成功登录(作为用户)是在2016-11-18 14:30:54
从…起
swtch-16-57-240#
swtch-16-57-240#形态t
swtch-16-57-240(配置)#int 8;209R
swtch-16-57-240(eth-8)#启用
swtch-16-57-240(eth-8)#wr膜
swtch-16-57-240(eth-8)#结束
swtch-16-57-240#注销
是否要注销[是/否]?Y
与远程主机关闭的交换机的连接。
与开关的连接关闭。
user@user-站点:/config/scripts$;209R^C
user@user-站点:/config/scripts$

这可能是一个模糊不清的控制序列吗?以R结尾的唯一vt100序列是:

Cursor position report        CPR        ESC [ Pl ; Pc R
其中,
Pl
Pc
是光标位置的行号和列号的整数(请参阅)

简单的解决方案可能是运行ssh,如:

set env(TERM) dumb
spawn env TERM=dumb ssh -o StrictHostKeyChecking=no user@switch
而更难的方法是以某种方式剥离逃逸序列。
同时尝试将
dumb
更改为
vt100
(当前设置为什么?

该“简易解决方案”仍然会导致错误输出。我会调查的。任何其他的输入都是非常感谢的。如果发送expect脚本控制序列,您应该看到会发生什么
ssh
进入localhost并运行一个脚本,该脚本会回显类似于路由器的输出,也会回显类似CPR的转义序列。在这种情况下,有一个名为vttest的程序可能会有所帮助。