大家好,
需求简单的说是向HP server(iLO3)发送一些维护指令,然后接收输入。手动输入没有问题,现在想用程序自动完成。
我本想用expect简单实现,不过却发现ssh连接建立后,原本输入的指令发送不过去!(我发送的是show /system1/bootconfig1,结果变成了so)
我现在怀疑写perl程序做连接是不是会有同样的问题,不知有没有兄弟有相关经验,能请给点建议。
C:\Documents and Settings\jiaqianz\Desktop>expect ssh.expect
spawn ssh -l admin xxx.xxx.xxx.xxx
admin@xxx.xxx.xxx.xxx's password:
User:admin logged-in to ILOCNG029THY4.(xxx.xxx.xxx.xxx)
iLO 3 Advanced 1.05 at Jun 01 2010
Server Name: server156
Server Power: On</>hpiLO-> so(程序很久不出来,于是我按了ctrl c,下面是debug模式,执行结果相同)
C:\Documents and Settings\jiaqianz\Desktop>expect -d ssh.expect
expect version 5.26
argv[0] = expect argv[1] = -d argv[2] = ssh.expect
set argc 0
set argv0 "ssh.expect"
set argv ""
executing commands from command file ssh.expect
spawn ssh -l admin xxx.xxx.xxx.xxx
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {4016}expect: does "" (spawn_id 4) match glob pattern "password:"? no
admin@xxx.xxx.xxx.xxx's password:
expect: does "admin@xxx.xxx.xxx.xxx's password: " (spawn_id 4) match glob patter
n "password:"? yes
expect: set expect_out(0,string) "password:"
expect: set expect_out(spawn_id) "4"
expect: set expect_out(buffer) "admin@xxx.xxx.xxx.xxx's password:"
send: sending "password\r" to { 4 }expect: does " " (spawn_id 4) match glob pattern "hpiLO->"? noUser:admin logged-in to ILOCNG029THY4.(xxx.xxx.xxx.xxx)
iLO 3 Advanced 1.05 at Jun 01 2010
Server Name: server156
Server Power: On</>hpiLO->
expect: does " \nUser:admin logged-in to ILOCNG029THY4.(xxx.xxx.xxx.xxx)\r\niLO
3 Advanced 1.05 at Jun 01 2010\r\nServer Name: server156\r\nServer Power: On\r\
n\n</>hpiLO-> " (spawn_id 4) match glob pattern "hpiLO->"? yes
expect: set expect_out(0,string) "hpiLO->"
expect: set expect_out(spawn_id) "4"
expect: set expect_out(buffer) " \nUser:admin logged-in to ILOCNG029THY4.(xxx.xxx.xxx.xxx)\r\niLO 3 Advanced 1.05 at Jun 01 2010\r\nServer Name: server156\r\nS
erver Power: On\r\n\n</>hpiLO->"
send: sending "show /system1/bootconfig1\r" to { 4 }expect: does " " (spawn_id 4) match glob pattern "hpiLO->"? no
so
expect: does " so" (spawn_id 4) match glob pattern "hpiLO->"? no(程序死在这里不出来,于是我再次按了ctrl c)
sighandler: handling signal(2)
async event handler: Tcl_Eval(exit)C:\Documents and Settings\jiaqianz\Desktop>type ssh.expect
spawn ssh -l admin xxx.xxx.xxx.xxx
set timeout -1
expect "password:"
sleep 1
send "password\r"
sleep 1
expect "hpiLO->"
sleep 1
send "show /system1/bootconfig1\r"
sleep 1
expect "hpiLO->"
send "exit\r"C:\Documents and Settings\jiaqianz\Desktop>
没有评论:
发表评论