红联Linux门户
Linux帮助

一个自动执行scp拷贝程序出错

发布时间:2011-12-05 21:07:18来源:红联作者:cai800315
我自己写了一个简单的自动执行scp拷贝程序,程序的进程基本是这样的。首先,登陆到206主机,206主机从202主机上拷贝一份文件到本机。但是执行时出现下面的问题:

ssh: connect to host 192.168.0.202 port 22: Connection refused
expect: spawn id exp7 not open
while executing
"expect -nobrace -re ~\]# {
send "\r"

} timeout {
exit 1
}"
invoked from within
"expect {
-re "$cmd_prompt"

{
send "\r"

}
timeout
{
exit 1
}
}"
(file "auto_copy_scp.exp" line 82)



下面为全部的程序:


#!/usr/bin/expect -f
set loginuser "root"
#set ipaddr "192.168.1.104"
set ip202 "192.168.0.202"
set ip206 "192.168.0.206"
set passwd206 "123456"
set passwd202 "123456"
#set loginpass "123456"
#set newpass "654321"
set cmd_prompt "~]#"


spawn ssh $loginuser@$ip206

set timeout 300

expect {
-re "Are you sure you want to continue connecting (yes/no)?"
{
send "yes\r"
}
-re "password:"
{
send "$passwd206\r"
}
-re "Permission denied, please try again."
{
exit
}
-re "Connection refused"
{
exit
}
timeout
{
exit
}
eof
{
exit
}
}

expect {
-re "password:"
{
send "$passwd206\r"
}

-re "$cmd_prompt"
{
send "\r"
}
}






#spawn passwd
spawn scp $loginuser@$ip202:/root/Win2003-32bit-sp2.iso /root

expect {
-re "Are you sure you want to continue connecting (yes/no)?"
{
send "yes\r"
}
-re "password:"
{
send "$passwd202\r"
}
timeout
{
exit 1
}

}
#set timeout 30000


expect {
-re "$cmd_prompt"

{
send "\r"
}
timeout
{
exit 1
}
}
#expect eof
exit


请大侠们指点指点。谢谢!
文章评论

共有 1 条评论

  1. cai800315 于 2011-12-07 22:48:23发表:

    哦,怎么没有回啊,是不是问题太简单啦,大家觉得不值得回吗?可是对我来说,却是一个困扰很久的问题啦,大虾们,给点帮助者吧。