首页 新闻 赞助 找找看

expect 脚本报‘spawn id exp6 not open while executing "expect eof"’错的问题怎么解决

0
悬赏园豆:20 [已关闭问题] 关闭于 2013-10-01 12:54

先贴代码:
#! /bin/bash
#transfile.sh 传文件到服务器上(支持多台服务器和指定IP)
#读取服务器账号密码文件

args=$#
if test $args == 0
    then
        echo "请传参数"
        exit
    elif test $args == 1
        then
            file=$1
    elif test $args == 2
        then
            server=$1
            file=$2
fi

if [ -d $file ]
    then
        echo 'Sorry本脚本只支持单个文件上传!'
        exit 0
fi

cat /home/hwhang/myroot/psw | while read line
do
    server1=`echo $line | awk '{print $1}'`
    serverip=`echo $line | awk '{print $2}'`
    username=`echo $line | awk '{print $3}'`
    psw=`echo $line | awk '{print $4}'`
    if test $args == 2
        then
        /home/hwhang/myroot/transfile.exp $username $psw $serverip $file
        break
    fi
    /home/hwhang/myroot/transfile.exp $username $psw $serverip $file
done
-------------------
#! /usr/bin/expect -f

#transfile.exp  expect 单次/单个文件上传脚本

set username [lindex $argv 0]
set psw1 [lindex $argv 1]
append psw $psw1 "\n"
set srverip [lindex $argv 2]
set file [lindex $argv 3]
set timeout -1

spawn scp -P12258 $file $username@$srverip:$file
expect {
    "(yes/no)?" {
        send "yes\n"
        expect "password:" {
            send $psw
        }
    }
    "password:" {
        send $psw
    }
}
expect eof



--------------------
执行后当最后一台服务器传完时报如下错误:

expect: spawn id exp6 not open
    while executing
"expect eof"
    (file "/home/hwhang/myroot/transfile.exp" line 24)


不明白。为什么,请教一下大牛们。。。。

D调e学痞的主页 D调e学痞 | 菜鸟二级 | 园豆:204
提问于:2013-09-06 14:21
< >
分享
所有回答(1)
0

大概应该是。。。不知,,为什么不人解答的,,

D调e学痞 | 园豆:204 (菜鸟二级) | 2013-10-01 11:02
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册