分页: 1 / 1

expect问题求教

发表于 : 2010-01-06 17:23
kingofnet
我是菜鸟 :em03
已经试验成功的脚本
#!expect
set remotehost [lindex $argv 0]
spawn ssh $remotehost
expect "*password:*"
send "xxxxx\n"
interact
exit
#ssh.exp
然后在另一个shell里调用
#!sh
eval "./ssh.exp xxx.xxx.xxx.xxx"


现在遇到这样一个问题,如果初次连接一台主机会提问:
The authenticity of host '10.204.176.25 (10.204.176.25)' can't be established.
RSA key fingerprint is 7a:76:b4:b2:e2:a8:50:44:03:d7:1a:1c:1a:9d:78:46.
Are you sure you want to continue connecting (yes/no)?
所以我改动了一下ssh.exp

expect "*password:*" {send "111111\n"} "*yes/no*" {send "yes\n"}
interact;
exit;
但是这样一旦出现提问yes/no,确实可以回答yes,但后面出现的密码就无能为力了
请教大家该怎么改?谢谢!

Re: expect问题求教

发表于 : 2010-01-06 17:31
O_O_BOT
irc <fwv> say: 没用过expectr 水下。。

Re: expect问题求教

发表于 : 2010-01-07 9:59
little_gg

代码: 全选

#!expect
set remotehost [lindex $argv 0]
spawn ssh $remotehost
expect -exact "(yes/no)"
send -- "yes\r"
expect -exact "Password:"
send -- "$pass1\r"
interact
exit

这样呢

Re: expect问题求教

发表于 : 2010-01-07 11:12
kingofnet
little_gg 写了:

代码: 全选

#!expect
set remotehost [lindex $argv 0]
spawn ssh $remotehost
expect -exact "(yes/no)"
send -- "yes\r"
expect -exact "Password:"
send -- "$pass1\r"
interact
exit

这样呢
这个没有成功,改成下面这个就好了,不过同样谢谢!

代码: 全选

expect "*password:*" {send "111111\n"} "*yes/no*" {send "yes\n"; expect "*password:*"; send "111111\n";}

Re: expect问题求教

发表于 : 2010-01-07 11:17
kingofnet
O_O_BOT 写了:irc <fwv> say: 没用过expectr 水下。。
水贴光荣~~