免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1715 | 回复: 3
打印 上一主题 下一主题

请教expect脚本中的一个错误 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-12-14 17:16 |只看该作者 |倒序浏览
脚本代码如下:
  1. #!/usr/local/bin/expect

  2. spawn telnet 192.168.150.205

  3. set port [ lindex $argv 1 ]

  4. expect "Password:"

  5. send "123456\r"

  6. expect "<sw100m03>"

  7. send "system-view\r"

  8. expect "System"


  9. send "interface Ethernet 1/0/$port\r"

  10. expect "sw100m03-Ethernet1/0/$port"

  11. send "port hybrid pvid vlan 1\r"
复制代码
出现错误如下:
spawn telnet 192.168.150.205
Trying 192.168.150.205...
Connected to 192.168.150.205 (192.168.150.205).
Escape character is '^]'.

********************************************************************************
*  Copyright(c) 1998-2006 Huawei Technologies Co., Ltd.  All rights reserved.  *
*  Without the owner's prior written consent,                                  *
*  no decompiling or reverse-engineering shall be allowed.                     *
********************************************************************************


Login authentication


Password:
<sw100m03>
%Jun 20 08:34:40:668 2000 sw100m03 SHELL/5/LOGIN:- 1 - VTY(192.168.150.203) in unit1 loginsystem-view
System View: return to User View with Ctrl+Z.
[sw100m03]interface Ethernet 1/0/
                             ^
% Wrong parameter found at '^' position.

个人感觉是因为使用变量port导致的,但是不明白为什么会出现这样的错误,还请大侠们指教

论坛徽章:
0
2 [报告]
发表于 2010-12-14 17:40 |只看该作者
回复 1# superhappy1


    你的第一个参数区哪了,
这个不是第二个参数吗
set port [ lindex $argv 1 ]
照你的脚本应该是
set port [ lindex $argv 0 ]
才对吧

论坛徽章:
0
3 [报告]
发表于 2010-12-15 10:54 |只看该作者
argv 1不是第一个参数吗

论坛徽章:
0
4 [报告]
发表于 2010-12-15 11:08 |只看该作者
回复 2# xiaopan3322

谢谢,是我搞错了
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP