本文介绍了无法在Expect脚本中识别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的期望脚本中出现了一些问题.我生成了一个scp文件上传,但是无法识别eof.在脚本继续执行之前,期望值已超时.

i have got some problems in my expect script.I am spawning a scp file upload but the eof is not recognized.The expect rans into the timeout before the script goes on.

我在做什么错??

这是脚本

    function ssh_upload_file () {

test_log INFO "Uploading File $3 to Device $2 with a $1 seconds timeout" "ssh_upload_file"
last_log_entry_to_detail

expect <<- DONE
set outfilename "$DETAIL_LOG"
log_file "$DETAIL_LOG";

set timeout $1
set lantime_ip $2

system "touch  ~/.ssh/known_hosts"
system "ssh-keygen -R $2"
spawn /bin/bash
sleep 3
send_user "Uploading File via SSH...\n"
send "scp $2 $3:$4 || echo FWTEST_SSH_RESULT=\$?\n"
expect "assword:" {
        after 1000
        send "$DUT_PWD\r"
        #set timeout 5
        #expect "y/n"
        #send "n\n"
        #set timeout $1
        #expect "#"
        #send "no_shell_timeout\n"
}
expect eof
send_user "Done."
log_file
exit 0
expect eof
DONE
LAST_ERROR=$?
return $LAST_ERROR
}

推荐答案

您生成了一个bash shell,并发送了一个scp命令. scp完成后,您将坐在bash提示符下.您需要先向bash发送exit命令,然后才能看到eof.

You spawn a bash shell, and send an scp command. When scp completes, you're sitting at a bash prompt. You need to send bash an exit command before you'll see eof.

或者,除了捕获scp命令的输出之外,您在该bash会话中没有执行任何操作,

Alternatively, you're not doing anything in that bash session except capture the output of the scp command which you can do like this:

spawn scp $2 $3:$4
expect "assword:"
send "$DUT_PWD\r"
expect eof
set info [wait]
puts "FWTEST_SSH_RESULT=[lindex [set info] 3]"


解决Donal的评论:


Addressing Donal's comment:

spawn scp $2 $3:$4
expect {
    "assword:" {
        send "$DUT_PWD\r"
        exp_continue
    }
    eof
}
set info [wait]
puts "FWTEST_SSH_RESULT=[lindex [set info] 3]"

这篇关于无法在Expect脚本中识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 11:01