bash 获取发送:spawn id exp6 未打开错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23887797/
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:32:51  来源:igfitidea点击:

getting send: spawn id exp6 not open error

rubybashshell

提问by user2622247

I know that this issue has many solutions mentioned here, but I am middle of this issue. I have created a ruby script snaps.rb.

我知道这个问题在这里提到了很多解决方案,但我是这个问题的中间人。我创建了一个 ruby​​ 脚本snaps.rb

This script for deleting the lvm snapshots. following code causing the problem

此脚本用于删除 lvm 快照。以下代码导致问题

`/usr/bin/expect <<delim
exp_internal 0
set timeout 20
spawn echo itsme | sudo -S lvremove #{snap_name}
expect {Do you really want to remove active logical volume #{name}? [y/n]:}
send "y\r"
expect eof 
delim`

snap_nameis my snapshot nameand I am using expect for passing y or n to the command input. and I am using backtick(``)for executing the shell command from ruby. but I getting following error.

snap_name是我的快照名称,我使用 expect 将 y 或 n 传递给命令输入。我正在使用反引号(``)从 ruby​​ 执行 shell 命令。但我收到以下错误。

send: spawn id exp6 not open
    while executing
""end "n

How can I resolve this error.

我该如何解决这个错误。

采纳答案by shrikant1712

Seperate out echo itsme | sudo -S lvremove #{snap_name}

分离出来 echo itsme | sudo -S lvremove #{snap_name}

try this

尝试这个

`/usr/bin/expect <<delim
exp_internal 0
set timeout 20
spawn sudo lvremove #{snap_name}
send "itsme\r"
expect {Do you really want to remove active logical volume #{name}? [y/n]:}
send "y\r"
expect eof 
delim`