首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >expect脚本有错误字符

expect脚本有错误字符
EN

Stack Overflow用户
提问于 2016-11-18 21:39:55
回答 1查看 164关注 0票数 1

我的脚本ssh进入了HP交换机,并对接口进行了更改。我不知道是什么导致了输出中的错误字符(参见粗体)。

我的剧本:

代码语言:javascript
复制
#!/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

代码语言:javascript
复制
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$
EN

回答 1

Stack Overflow用户

发布于 2016-11-18 21:59:49

会不会是一个被咀嚼的控制序列?唯一以R结尾的vt100序列是:

代码语言:javascript
复制
Cursor position report        CPR        ESC [ Pl ; Pc R

其中PlPc是光标位置的行号和列号的整数(参见http://www.vt100.net/docs/vt102-ug/appendixc.html)。

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

代码语言:javascript
复制
set env(TERM) dumb
spawn env TERM=dumb ssh -o StrictHostKeyChecking=no user@switch

更难的方法是从某种程度上剥去逃逸序列。还可以尝试将dumb更改为vt100 (它当前设置为什么?)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40686347

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档