- 论坛徽章:
- 0
|
说不明白。直接贴代码吧。
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 }
|
|
|