Define input number with expect
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I am trying to automate the deployment of a Docker container. Three prompts need to be filled in manually in order to proceed with the deployment. However, they are not to be filled in after each other. The order in which these fields appear is very odd. First off it asks for a password and a confirmation (two fields following each other). Then, the OpenVPN script does its thing and then needs an FQDN to generate a certificate I believe.
So: I'm wondering if I can tell expect
to fill in value X for field X and once the input field Y appears, fill in value Y. In other words, can I tell expect
to automatically recognize input prompts and fill them in accordingly?
shell-script expect
 |Â
show 3 more comments
up vote
1
down vote
favorite
I am trying to automate the deployment of a Docker container. Three prompts need to be filled in manually in order to proceed with the deployment. However, they are not to be filled in after each other. The order in which these fields appear is very odd. First off it asks for a password and a confirmation (two fields following each other). Then, the OpenVPN script does its thing and then needs an FQDN to generate a certificate I believe.
So: I'm wondering if I can tell expect
to fill in value X for field X and once the input field Y appears, fill in value Y. In other words, can I tell expect
to automatically recognize input prompts and fill them in accordingly?
shell-script expect
I recommend Ansible.
â Rui F Ribeiro
Feb 7 at 11:09
@RuiFRibeiro Ansible introduces more challenges than the problem it's supposed to solve for this specific project. We do most of our deployment with Ansible though.
â William Edwards
Feb 7 at 11:12
I have usedexpect
in the past. It is a bit limited for this kind of actions, and involves a lot of babysitting over time.
â Rui F Ribeiro
Feb 7 at 11:13
@RuiFRibeiro I am aware.
â William Edwards
Feb 7 at 11:13
1
The answer to your current question is: yes, probably. Can you show examples of those prompts and values? Then someone here might be able to provide a useful answer.
â Jeff Schaller
Feb 7 at 11:35
 |Â
show 3 more comments
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am trying to automate the deployment of a Docker container. Three prompts need to be filled in manually in order to proceed with the deployment. However, they are not to be filled in after each other. The order in which these fields appear is very odd. First off it asks for a password and a confirmation (two fields following each other). Then, the OpenVPN script does its thing and then needs an FQDN to generate a certificate I believe.
So: I'm wondering if I can tell expect
to fill in value X for field X and once the input field Y appears, fill in value Y. In other words, can I tell expect
to automatically recognize input prompts and fill them in accordingly?
shell-script expect
I am trying to automate the deployment of a Docker container. Three prompts need to be filled in manually in order to proceed with the deployment. However, they are not to be filled in after each other. The order in which these fields appear is very odd. First off it asks for a password and a confirmation (two fields following each other). Then, the OpenVPN script does its thing and then needs an FQDN to generate a certificate I believe.
So: I'm wondering if I can tell expect
to fill in value X for field X and once the input field Y appears, fill in value Y. In other words, can I tell expect
to automatically recognize input prompts and fill them in accordingly?
shell-script expect
edited Feb 7 at 12:49
Vlastimil
6,3711146119
6,3711146119
asked Feb 7 at 11:06
William Edwards
3211420
3211420
I recommend Ansible.
â Rui F Ribeiro
Feb 7 at 11:09
@RuiFRibeiro Ansible introduces more challenges than the problem it's supposed to solve for this specific project. We do most of our deployment with Ansible though.
â William Edwards
Feb 7 at 11:12
I have usedexpect
in the past. It is a bit limited for this kind of actions, and involves a lot of babysitting over time.
â Rui F Ribeiro
Feb 7 at 11:13
@RuiFRibeiro I am aware.
â William Edwards
Feb 7 at 11:13
1
The answer to your current question is: yes, probably. Can you show examples of those prompts and values? Then someone here might be able to provide a useful answer.
â Jeff Schaller
Feb 7 at 11:35
 |Â
show 3 more comments
I recommend Ansible.
â Rui F Ribeiro
Feb 7 at 11:09
@RuiFRibeiro Ansible introduces more challenges than the problem it's supposed to solve for this specific project. We do most of our deployment with Ansible though.
â William Edwards
Feb 7 at 11:12
I have usedexpect
in the past. It is a bit limited for this kind of actions, and involves a lot of babysitting over time.
â Rui F Ribeiro
Feb 7 at 11:13
@RuiFRibeiro I am aware.
â William Edwards
Feb 7 at 11:13
1
The answer to your current question is: yes, probably. Can you show examples of those prompts and values? Then someone here might be able to provide a useful answer.
â Jeff Schaller
Feb 7 at 11:35
I recommend Ansible.
â Rui F Ribeiro
Feb 7 at 11:09
I recommend Ansible.
â Rui F Ribeiro
Feb 7 at 11:09
@RuiFRibeiro Ansible introduces more challenges than the problem it's supposed to solve for this specific project. We do most of our deployment with Ansible though.
â William Edwards
Feb 7 at 11:12
@RuiFRibeiro Ansible introduces more challenges than the problem it's supposed to solve for this specific project. We do most of our deployment with Ansible though.
â William Edwards
Feb 7 at 11:12
I have used
expect
in the past. It is a bit limited for this kind of actions, and involves a lot of babysitting over time.â Rui F Ribeiro
Feb 7 at 11:13
I have used
expect
in the past. It is a bit limited for this kind of actions, and involves a lot of babysitting over time.â Rui F Ribeiro
Feb 7 at 11:13
@RuiFRibeiro I am aware.
â William Edwards
Feb 7 at 11:13
@RuiFRibeiro I am aware.
â William Edwards
Feb 7 at 11:13
1
1
The answer to your current question is: yes, probably. Can you show examples of those prompts and values? Then someone here might be able to provide a useful answer.
â Jeff Schaller
Feb 7 at 11:35
The answer to your current question is: yes, probably. Can you show examples of those prompts and values? Then someone here might be able to provide a useful answer.
â Jeff Schaller
Feb 7 at 11:35
 |Â
show 3 more comments
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
Certainly, this is what expect is for. The exp_continue
command is the key here:
expect
"password: " send "$passwordr"; exp_continue
"confirmation" send "$confirmr"; exp_continue
"FQDN" send "$fqdnr"; exp_continue
"some other pattern"
Of course you'll have to change the quoted patterns so they match your actual case.
With this structure, the patterns can match in any order. The patterns don't even have to appear at all.
When "some other pattern" is seen, since there's no action block associated with it, it triggers the end of the encompassing expect command and the rest of the script can carry on.
For expect to be able to control a process, you must launch that process from within expect. Try this:
#!/bin/bash
port=$1
export hostname=$2
export OVPN_DATA="ovpn-data-$port"
docker volume create --name $OVPN_DATA
/usr/bin/expect <<'END_EXPECT'
set timeout -1
spawn docker run -v $env(OVPN_DATA):/etc/openvpn --rm kylemanna/openvpn ovpn_genconfig -u udp://$env(hostname)
expect
"Enter PEM pass phrase:"
# this should match whether it's the initial or confirmation prompt
send "secretr"
exp_continue
"Common Name"
send "$env(hostname)r"
exp_continue
eof
END_EXPECT
docker run -v $OVPN_DATA:/etc/openvpn --rm -it kylemanna/openvpn ovpn_initpki
docker run -dit --restart unless-stopped --name=$port -v $OVPN_DATA:/etc/openvpn -d -p $port:1194/udp --cap-add=NET_ADMIN kylemanna/openvpn
The code (second block) doesn't work. Variables aren't getting passed properly I suppose?no such variable (read trace on "env(hostname)") invoked from within
â William Edwards
Feb 7 at 19:27
did youexport
the shell variable hostname?
â glenn jackman
Feb 7 at 20:05
Yes. The certificate is not generated successfully:Options error: --dh fails with '/etc/openvpn/pki/dh.pem': No such file or directory (errno=2)
â William Edwards
Feb 7 at 20:12
I rewrote the code slightly and it seems to work now. Hold on.
â William Edwards
Feb 7 at 20:17
Gettingunable to load CA private key
now but I figured that can have many reasons, so I will debug further.
â William Edwards
Feb 7 at 20:26
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
Certainly, this is what expect is for. The exp_continue
command is the key here:
expect
"password: " send "$passwordr"; exp_continue
"confirmation" send "$confirmr"; exp_continue
"FQDN" send "$fqdnr"; exp_continue
"some other pattern"
Of course you'll have to change the quoted patterns so they match your actual case.
With this structure, the patterns can match in any order. The patterns don't even have to appear at all.
When "some other pattern" is seen, since there's no action block associated with it, it triggers the end of the encompassing expect command and the rest of the script can carry on.
For expect to be able to control a process, you must launch that process from within expect. Try this:
#!/bin/bash
port=$1
export hostname=$2
export OVPN_DATA="ovpn-data-$port"
docker volume create --name $OVPN_DATA
/usr/bin/expect <<'END_EXPECT'
set timeout -1
spawn docker run -v $env(OVPN_DATA):/etc/openvpn --rm kylemanna/openvpn ovpn_genconfig -u udp://$env(hostname)
expect
"Enter PEM pass phrase:"
# this should match whether it's the initial or confirmation prompt
send "secretr"
exp_continue
"Common Name"
send "$env(hostname)r"
exp_continue
eof
END_EXPECT
docker run -v $OVPN_DATA:/etc/openvpn --rm -it kylemanna/openvpn ovpn_initpki
docker run -dit --restart unless-stopped --name=$port -v $OVPN_DATA:/etc/openvpn -d -p $port:1194/udp --cap-add=NET_ADMIN kylemanna/openvpn
The code (second block) doesn't work. Variables aren't getting passed properly I suppose?no such variable (read trace on "env(hostname)") invoked from within
â William Edwards
Feb 7 at 19:27
did youexport
the shell variable hostname?
â glenn jackman
Feb 7 at 20:05
Yes. The certificate is not generated successfully:Options error: --dh fails with '/etc/openvpn/pki/dh.pem': No such file or directory (errno=2)
â William Edwards
Feb 7 at 20:12
I rewrote the code slightly and it seems to work now. Hold on.
â William Edwards
Feb 7 at 20:17
Gettingunable to load CA private key
now but I figured that can have many reasons, so I will debug further.
â William Edwards
Feb 7 at 20:26
add a comment |Â
up vote
2
down vote
accepted
Certainly, this is what expect is for. The exp_continue
command is the key here:
expect
"password: " send "$passwordr"; exp_continue
"confirmation" send "$confirmr"; exp_continue
"FQDN" send "$fqdnr"; exp_continue
"some other pattern"
Of course you'll have to change the quoted patterns so they match your actual case.
With this structure, the patterns can match in any order. The patterns don't even have to appear at all.
When "some other pattern" is seen, since there's no action block associated with it, it triggers the end of the encompassing expect command and the rest of the script can carry on.
For expect to be able to control a process, you must launch that process from within expect. Try this:
#!/bin/bash
port=$1
export hostname=$2
export OVPN_DATA="ovpn-data-$port"
docker volume create --name $OVPN_DATA
/usr/bin/expect <<'END_EXPECT'
set timeout -1
spawn docker run -v $env(OVPN_DATA):/etc/openvpn --rm kylemanna/openvpn ovpn_genconfig -u udp://$env(hostname)
expect
"Enter PEM pass phrase:"
# this should match whether it's the initial or confirmation prompt
send "secretr"
exp_continue
"Common Name"
send "$env(hostname)r"
exp_continue
eof
END_EXPECT
docker run -v $OVPN_DATA:/etc/openvpn --rm -it kylemanna/openvpn ovpn_initpki
docker run -dit --restart unless-stopped --name=$port -v $OVPN_DATA:/etc/openvpn -d -p $port:1194/udp --cap-add=NET_ADMIN kylemanna/openvpn
The code (second block) doesn't work. Variables aren't getting passed properly I suppose?no such variable (read trace on "env(hostname)") invoked from within
â William Edwards
Feb 7 at 19:27
did youexport
the shell variable hostname?
â glenn jackman
Feb 7 at 20:05
Yes. The certificate is not generated successfully:Options error: --dh fails with '/etc/openvpn/pki/dh.pem': No such file or directory (errno=2)
â William Edwards
Feb 7 at 20:12
I rewrote the code slightly and it seems to work now. Hold on.
â William Edwards
Feb 7 at 20:17
Gettingunable to load CA private key
now but I figured that can have many reasons, so I will debug further.
â William Edwards
Feb 7 at 20:26
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
Certainly, this is what expect is for. The exp_continue
command is the key here:
expect
"password: " send "$passwordr"; exp_continue
"confirmation" send "$confirmr"; exp_continue
"FQDN" send "$fqdnr"; exp_continue
"some other pattern"
Of course you'll have to change the quoted patterns so they match your actual case.
With this structure, the patterns can match in any order. The patterns don't even have to appear at all.
When "some other pattern" is seen, since there's no action block associated with it, it triggers the end of the encompassing expect command and the rest of the script can carry on.
For expect to be able to control a process, you must launch that process from within expect. Try this:
#!/bin/bash
port=$1
export hostname=$2
export OVPN_DATA="ovpn-data-$port"
docker volume create --name $OVPN_DATA
/usr/bin/expect <<'END_EXPECT'
set timeout -1
spawn docker run -v $env(OVPN_DATA):/etc/openvpn --rm kylemanna/openvpn ovpn_genconfig -u udp://$env(hostname)
expect
"Enter PEM pass phrase:"
# this should match whether it's the initial or confirmation prompt
send "secretr"
exp_continue
"Common Name"
send "$env(hostname)r"
exp_continue
eof
END_EXPECT
docker run -v $OVPN_DATA:/etc/openvpn --rm -it kylemanna/openvpn ovpn_initpki
docker run -dit --restart unless-stopped --name=$port -v $OVPN_DATA:/etc/openvpn -d -p $port:1194/udp --cap-add=NET_ADMIN kylemanna/openvpn
Certainly, this is what expect is for. The exp_continue
command is the key here:
expect
"password: " send "$passwordr"; exp_continue
"confirmation" send "$confirmr"; exp_continue
"FQDN" send "$fqdnr"; exp_continue
"some other pattern"
Of course you'll have to change the quoted patterns so they match your actual case.
With this structure, the patterns can match in any order. The patterns don't even have to appear at all.
When "some other pattern" is seen, since there's no action block associated with it, it triggers the end of the encompassing expect command and the rest of the script can carry on.
For expect to be able to control a process, you must launch that process from within expect. Try this:
#!/bin/bash
port=$1
export hostname=$2
export OVPN_DATA="ovpn-data-$port"
docker volume create --name $OVPN_DATA
/usr/bin/expect <<'END_EXPECT'
set timeout -1
spawn docker run -v $env(OVPN_DATA):/etc/openvpn --rm kylemanna/openvpn ovpn_genconfig -u udp://$env(hostname)
expect
"Enter PEM pass phrase:"
# this should match whether it's the initial or confirmation prompt
send "secretr"
exp_continue
"Common Name"
send "$env(hostname)r"
exp_continue
eof
END_EXPECT
docker run -v $OVPN_DATA:/etc/openvpn --rm -it kylemanna/openvpn ovpn_initpki
docker run -dit --restart unless-stopped --name=$port -v $OVPN_DATA:/etc/openvpn -d -p $port:1194/udp --cap-add=NET_ADMIN kylemanna/openvpn
edited Feb 7 at 16:14
answered Feb 7 at 13:36
glenn jackman
46.4k265102
46.4k265102
The code (second block) doesn't work. Variables aren't getting passed properly I suppose?no such variable (read trace on "env(hostname)") invoked from within
â William Edwards
Feb 7 at 19:27
did youexport
the shell variable hostname?
â glenn jackman
Feb 7 at 20:05
Yes. The certificate is not generated successfully:Options error: --dh fails with '/etc/openvpn/pki/dh.pem': No such file or directory (errno=2)
â William Edwards
Feb 7 at 20:12
I rewrote the code slightly and it seems to work now. Hold on.
â William Edwards
Feb 7 at 20:17
Gettingunable to load CA private key
now but I figured that can have many reasons, so I will debug further.
â William Edwards
Feb 7 at 20:26
add a comment |Â
The code (second block) doesn't work. Variables aren't getting passed properly I suppose?no such variable (read trace on "env(hostname)") invoked from within
â William Edwards
Feb 7 at 19:27
did youexport
the shell variable hostname?
â glenn jackman
Feb 7 at 20:05
Yes. The certificate is not generated successfully:Options error: --dh fails with '/etc/openvpn/pki/dh.pem': No such file or directory (errno=2)
â William Edwards
Feb 7 at 20:12
I rewrote the code slightly and it seems to work now. Hold on.
â William Edwards
Feb 7 at 20:17
Gettingunable to load CA private key
now but I figured that can have many reasons, so I will debug further.
â William Edwards
Feb 7 at 20:26
The code (second block) doesn't work. Variables aren't getting passed properly I suppose?
no such variable (read trace on "env(hostname)") invoked from within
â William Edwards
Feb 7 at 19:27
The code (second block) doesn't work. Variables aren't getting passed properly I suppose?
no such variable (read trace on "env(hostname)") invoked from within
â William Edwards
Feb 7 at 19:27
did you
export
the shell variable hostname?â glenn jackman
Feb 7 at 20:05
did you
export
the shell variable hostname?â glenn jackman
Feb 7 at 20:05
Yes. The certificate is not generated successfully:
Options error: --dh fails with '/etc/openvpn/pki/dh.pem': No such file or directory (errno=2)
â William Edwards
Feb 7 at 20:12
Yes. The certificate is not generated successfully:
Options error: --dh fails with '/etc/openvpn/pki/dh.pem': No such file or directory (errno=2)
â William Edwards
Feb 7 at 20:12
I rewrote the code slightly and it seems to work now. Hold on.
â William Edwards
Feb 7 at 20:17
I rewrote the code slightly and it seems to work now. Hold on.
â William Edwards
Feb 7 at 20:17
Getting
unable to load CA private key
now but I figured that can have many reasons, so I will debug further.â William Edwards
Feb 7 at 20:26
Getting
unable to load CA private key
now but I figured that can have many reasons, so I will debug further.â William Edwards
Feb 7 at 20:26
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f422515%2fdefine-input-number-with-expect%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
I recommend Ansible.
â Rui F Ribeiro
Feb 7 at 11:09
@RuiFRibeiro Ansible introduces more challenges than the problem it's supposed to solve for this specific project. We do most of our deployment with Ansible though.
â William Edwards
Feb 7 at 11:12
I have used
expect
in the past. It is a bit limited for this kind of actions, and involves a lot of babysitting over time.â Rui F Ribeiro
Feb 7 at 11:13
@RuiFRibeiro I am aware.
â William Edwards
Feb 7 at 11:13
1
The answer to your current question is: yes, probably. Can you show examples of those prompts and values? Then someone here might be able to provide a useful answer.
â Jeff Schaller
Feb 7 at 11:35