Reputation: 3590
I have installed expect command on CentOS 7 with yum install expect -y
. I want to automate some input in my script but it seems like it doesn't interpret in bash anymore.
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
.
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
If I make 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"
Upvotes: 1
Views: 19505
Reputation: 207415
You basically want an expect
script inside a bash
script something like this:
#!/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
Upvotes: 3