首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

expetc 脚本报‘spawn id exp6 not open while executing "expect eof"’错的有关问题

2013-10-02 
expetc 脚本报‘spawn id exp6 not open while executing expect eof’错的问题先贴代码:#! /bin/bash#tra

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)


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







脚本
[解决办法]
应该是
scp -P12258 $file $username@$srverip:$file
这条命令没有成功执行(比如连接被拒绝,或者命令格式错误),或者没有进入交互界面(比如直接用ssh key验证),
导致expect无法与scp进程交互。

你可以试试手动执行这条命令,看有什么效果。

热点排行