expect问题求教

sh/bash/dash/ksh/zsh等Shell脚本
回复
kingofnet
帖子: 15
注册时间: 2010-01-06 14:21

expect问题求教

#1

帖子 kingofnet » 2010-01-06 17:23

我是菜鸟 :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,但后面出现的密码就无能为力了
请教大家该怎么改?谢谢!
头像
O_O_BOT
帖子: 2461
注册时间: 2009-05-20 19:32

Re: expect问题求教

#2

帖子 O_O_BOT » 2010-01-06 17:31

irc <fwv> say: 没用过expectr 水下。。
irc 聊天室
ubuntu-cn 的irc 频道为
irc.ubuntu.com 8001 #ubuntu-cn
UTF8编码 可用 irssi xchat pidgin weechat 登录

http://webchat.freenode.net/?channels=ubuntu-cn
[url]irc://irc.freenode.net/ubuntu-cn[/url]
little_gg
帖子: 32
注册时间: 2008-01-29 9:09

Re: expect问题求教

#3

帖子 little_gg » 2010-01-07 9:59

代码: 全选

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

这样呢
kingofnet
帖子: 15
注册时间: 2010-01-06 14:21

Re: expect问题求教

#4

帖子 kingofnet » 2010-01-07 11:12

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";}
kingofnet
帖子: 15
注册时间: 2010-01-06 14:21

Re: expect问题求教

#5

帖子 kingofnet » 2010-01-07 11:17

O_O_BOT 写了:irc <fwv> say: 没用过expectr 水下。。
水贴光荣~~
回复