bash 发送预期脚本错误:执行“发送“密码”时 spawn id exp4 未打开

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24963917/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 10:57:50  来源:igfitidea点击:

Expect script error send: spawn id exp4 not open while executing "send "password""

linuxbashshellunixexpect

提问by Phi

I'm trying to run an expect script but I have an error:

我正在尝试运行一个期望脚本,但出现错误:

send: spawn id exp4 not open
    while executing
"send "password"

My script is very simple:

我的脚本很简单:

#!/usr/bin/expect -f
#!/usr/bin/env expect
#!/usr/bin/env export
#!/bin/sh
#!/bin/bash
spawn sftp -o IdentityFile=/home/localUser/MyPrivKeys_open.ppk [email protected]
expect "sftp.gatewayEnter passphrase for key '/home2/localUser/MyPrivKeys_open.ppk':"
send "passphrase\r"
expect "sftp>"
send "cd /home/localUser/localPath \r"
expect "sftp>"
send "mget myfile.xml /home/localUser/localPath \r"
set timeout 5
interact

What I do is editing my expect script in notepad.exe but when i upload my script i have to run next commands:

我所做的是在 notepad.exe 中编辑我的期望脚本,但是当我上传我的脚本时,我必须运行下一个命令:

dos2unix bash.sh -> converts dos file to a Unix file

dos2unix bash.sh -> 将 dos 文件转换为 Unix 文件

chmod +x bash.sh -> gives execution permission

chmod +x bash.sh -> 赋予执行权限

And finally i run my script:

最后我运行我的脚本:

./bash.sh

./bash.sh

But after that it sends that error. It is something really weird because i have another .sh file with the same structure and i am only changing paths where i get files

但在那之后它会发送那个错误。这真的很奇怪,因为我有另一个具有相同结构的 .sh 文件,我只是更改获取文件的路径

I think i need some help about it.

我想我需要一些帮助。

Thanks.

谢谢。

采纳答案by Phi

I have already fix it, it was an error in dos2unix command. I had to code it again over Ubuntu for avoiding to run dos2unix command.

我已经修复了,这是 dos2unix 命令中的错误。为了避免运行 dos2unix 命令,我不得不在 Ubuntu 上再次对其进行编码。