日期:2014-05-16  浏览次数:23690 次

expetc 脚本报‘spawn id exp6 not open while executing "expect eof"’错的问题
先贴代码:
#! /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/hwh/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/hwh/myroot/transfile.exp $username $psw $serverip $file
        break
    fi
    /home/hwh/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/hwh/myroot/transfile.exp" line 24)


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