免费注册 查看新帖 |

Chinaunix

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

请问关于expect参数传递的问题。 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-07-31 15:13 |只看该作者 |倒序浏览
说不明白。直接贴代码吧。

spawn ssh -p22 root@****
expect "password:"
send "******\r"
expect " ~]#"
send "/root/config1.sh $argv 1 $argv 2 $argv 3\r"
expect " ~]#"
send "/root/config2.sh\r"
close
exit 0
~

#expect test.sh 1 2 3
spawn ssh -p22 root@****
root@10.10.234.80's password:
Last login: Mon Jul 28 13:02:15 2008 from *****
[root@localhost ~]# /root/config1.sh 1 2 3 1 1 2 3 2 1 2 3 3


在向config1.sh传递参数的时候。总是莫名其妙的多几个参数。。

还有。。它总是少执行一条send语句(config2.sh没有被执行)。。

如果send只有语句只有一条,根本不执行,

下边是expect -d的调试信息
linux-qzyh:~ # expect -d test.sh 1 2 3
expect version 5.44.1.5
argv[0] = expect  argv[1] = -d  argv[2] = test.sh  argv[3] = 1  argv[4] = 2  argv[5] = 3
set argc 3
set argv0 "test.sh"
set argv "1 2 3"
executing commands from command file test.sh
spawn ssh -p22 root@*******
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {4141}

expect: does "" (spawn_id exp6) match glob pattern "password:"? no
root@*********'s password:
expect: does "root@10.10.234.80's password: " (spawn_id exp6) match glob pattern "password:"? yes
expect: set expect_out(0,string) "password:"
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "root@10.10.234.80's password:"
send: sending "*******\r" to { exp6 }

expect: does " " (spawn_id exp6) match glob pattern " ~]#"? no


expect: does " \r\n" (spawn_id exp6) match glob pattern " ~]#"? no
Last login: Mon Jul 28 13:04:28 2008 from *******

expect: does " \r\nLast login: Mon Jul 28 13:04:28 2008 from *******\r\r\n" (spawn_id exp6) match glob pattern " ~]#"? no

expect: does " \r\nLast login: Mon Jul 28 13:04:28 2008 from *******\r\r\n\u001b]0;root@localhost:~\u0007" (spawn_id exp6) match glob pattern " ~]#"? no
[root@localhost ~]#
expect: does " \r\nLast login: Mon Jul 28 13:04:28 2008 from *******\r\r\n\u001b]0;root@localhost:~\u0007[root@localhost ~]# " (spawn_id exp6) match glob pattern " ~]#"? yes
expect: set expect_out(0,string) " ~]#"
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) " \r\nLast login: Mon Jul 28 13:04:28 2008 from *******\r\r\n\u001b]0;root@localhost:~\u0007[root@localhost ~]#"
send: sending "/root/config1.sh 1 2 3 1 1 2 3 2 1 2 3 3\r" to { exp6 }

expect: does " " (spawn_id exp6) match glob pattern " ~]#"? no
/r
expect: does " /r" (spawn_id exp6) match glob pattern " ~]#"? no
oot/
expect: does " /root/" (spawn_id exp6) match glob pattern " ~]#"? no
con
expect: does " /root/con" (spawn_id exp6) match glob pattern " ~]#"? no
f
expect: does " /root/conf" (spawn_id exp6) match glob pattern " ~]#"? no
ig
expect: does " /root/config" (spawn_id exp6) match glob pattern " ~]#"? no
1
expect: does " /root/config1" (spawn_id exp6) match glob pattern " ~]#"? no
.s
expect: does " /root/config1.s" (spawn_id exp6) match glob pattern " ~]#"? no
h 1 2
expect: does " /root/config1.sh 1 2 " (spawn_id exp6) match glob pattern " ~]#"? no
3 1 1 2 3 2 1 2 3 3

expect: does " /root/config1.sh 1 2 3 1 1 2 3 2 1 2 3 3\r\n" (spawn_id exp6) match glob pattern " ~]#"? no

expect: does " /root/config1.sh 1 2 3 1 1 2 3 2 1 2 3 3\r\n\u001b]0;root@localhost:~\u0007" (spawn_id exp6) match glob pattern " ~]#"? no
[root@localhost ~]#
expect: does " /root/config1.sh 1 2 3 1 1 2 3 2 1 2 3 3\r\n\u001b]0;root@localhost:~\u0007[root@localhost ~]# " (spawn_id exp6) match glob pattern " ~]#"? yes
expect: set expect_out(0,string) " ~]#"
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) " /root/config1.sh 1 2 3 1 1 2 3 2 1 2 3 3\r\n\u001b]0;root@localhost:~\u0007[root@localhost ~]#"
send: sending "/root/config2.sh\r" to { exp6 }

论坛徽章:
0
2 [报告]
发表于 2008-07-31 16:40 |只看该作者
参数传递的问题已经解决 。。现在就是不解。它为什么总是少执行一条命令

论坛徽章:
0
3 [报告]
发表于 2008-07-31 18:30 |只看该作者
close 之前再加一句 expect " ~]#"
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP