[英]Expect command not found in script
I have installed expect command on CentOS 7 with yum install expect -y
.我已经使用
yum install expect -y
在 CentOS 7 上安装了 expect 命令。 I want to automate some input in my script but it seems like it doesn't interpret in bash anymore.我想在我的脚本中自动化一些输入,但它似乎不再在 bash 中解释了。
Here is my script :这是我的脚本:
#!/usr/bin/expect -f
homeDir="/home"
if [ $# -eq 1 ]; then
CLIENT="$1"
./easyrsa build-client-full "$CLIENT" nopass
elif [ $# -eq 2 ]; then
CLIENT="$1"
password="$2"
set timeout -1
spawn ./easyrsa build-client-full "$CLIENT"
expect "Enter PEM pass phrase:"
send -- "$password"
expect eof
else
echo "script <username> <password (optional)>"
fi
I made the script executable with chmod +x script
and run it like ./script
.我使用
chmod +x script
使脚本可执行并像./script
一样运行它。 The error I get :我得到的错误:
script: line11: spawn : command not found couldn't read file "Enter PEM pass phrase:": no such file or directory script: ligne13: send : command not found couldn't read file "eof": no such file or directory
脚本:line11:spawn:找不到命令无法读取文件“输入 PEM 密码:”:没有这样的文件或目录脚本:ligne13:发送:找不到命令无法读取文件“eof”:没有这样的文件或目录
If I make whereis expect
如果我让
whereis expect
I get :我得到:
expect: /usr/bin/expect /usr/share/man/man1/expect.1.gz
I would like to ask if there is some alternative without using another lib ?我想问一下不使用其他库是否有其他选择?
I also tried using this line of code but this doesn't give any return :我也尝试使用这行代码,但这没有任何回报:
echo "$password" | ./easyrsa build-client-full "$CLIENT"
You basically want an expect
script inside a bash
script something like this: 你基本上要一
expect
一个内部脚本bash
脚本是这样的:
#!/bin/bash
homeDir="/home"
if [ $# -eq 1 ]; then
CLIENT="$1"
./easyrsa build-client-full "$CLIENT" nopass
elif [ $# -eq 2 ]; then
CLIENT="$1"
password="$2"
/usr/bin/expect <<EOF
...
DO EXPECT STUFF
...
EOF
else
echo "script <username> <password (optional)>"
fi
The following is an example using sexpect (Expect for Shells) . 以下是使用sexpect(外壳期望)的示例。 Just FYI.
仅供参考。
#!/bin/bash
homeDir="/home"
if [ $# -eq 1 ]; then
CLIENT="$1"
./easyrsa build-client-full "$CLIENT" nopass
elif [ $# -eq 2 ]; then
CLIENT="$1"
password="$2"
export SEXPECT_SOCKFILE=/tmp/sexpect.tmp.$$.sock
sexpect spawn ./easyrsa build-client-full "$CLIENT"
sexpect expect "Enter PEM pass phrase:"
sexpect send -enter "$password"
sexpect expect -eof
sexpect wait
else
echo "script <username> <password (optional)>"
fi
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.