Can I use << EOF but let user to complete the input

Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
The need for this arose from the script below. It connects to a remote PC using anyconnect's vpn utility. First it asks for the one-time-password, connects, starts an RDP client and disconnects after the RPD client app has been closed.
if [ $# == 1 ]; then
ONE_TIME_PWD=$1;
else
printf "Enter the one-time password: ";
read ONE_TIME_PWD;
fi
vpn -s connect <domain> << EOF
<user>
<pin>$ONE_TIME_PWD
EOF
# Use some RDP client here like xfreerdp or rdesktop
vpn -s disconnect <domain>
The problem is that one-time-password may change during the execution of vpn -s connect <domain>. So I was curious whether it's possible to change the script so that it lets me enter the one-time-password after <pin> has been inserted automatically? I've tried it with head -c -1 to remove the last newline char but the input was still finished. Any other solution not based on EOF is acceptable.
bash here-document
add a comment |
up vote
1
down vote
favorite
The need for this arose from the script below. It connects to a remote PC using anyconnect's vpn utility. First it asks for the one-time-password, connects, starts an RDP client and disconnects after the RPD client app has been closed.
if [ $# == 1 ]; then
ONE_TIME_PWD=$1;
else
printf "Enter the one-time password: ";
read ONE_TIME_PWD;
fi
vpn -s connect <domain> << EOF
<user>
<pin>$ONE_TIME_PWD
EOF
# Use some RDP client here like xfreerdp or rdesktop
vpn -s disconnect <domain>
The problem is that one-time-password may change during the execution of vpn -s connect <domain>. So I was curious whether it's possible to change the script so that it lets me enter the one-time-password after <pin> has been inserted automatically? I've tried it with head -c -1 to remove the last newline char but the input was still finished. Any other solution not based on EOF is acceptable.
bash here-document
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
The need for this arose from the script below. It connects to a remote PC using anyconnect's vpn utility. First it asks for the one-time-password, connects, starts an RDP client and disconnects after the RPD client app has been closed.
if [ $# == 1 ]; then
ONE_TIME_PWD=$1;
else
printf "Enter the one-time password: ";
read ONE_TIME_PWD;
fi
vpn -s connect <domain> << EOF
<user>
<pin>$ONE_TIME_PWD
EOF
# Use some RDP client here like xfreerdp or rdesktop
vpn -s disconnect <domain>
The problem is that one-time-password may change during the execution of vpn -s connect <domain>. So I was curious whether it's possible to change the script so that it lets me enter the one-time-password after <pin> has been inserted automatically? I've tried it with head -c -1 to remove the last newline char but the input was still finished. Any other solution not based on EOF is acceptable.
bash here-document
The need for this arose from the script below. It connects to a remote PC using anyconnect's vpn utility. First it asks for the one-time-password, connects, starts an RDP client and disconnects after the RPD client app has been closed.
if [ $# == 1 ]; then
ONE_TIME_PWD=$1;
else
printf "Enter the one-time password: ";
read ONE_TIME_PWD;
fi
vpn -s connect <domain> << EOF
<user>
<pin>$ONE_TIME_PWD
EOF
# Use some RDP client here like xfreerdp or rdesktop
vpn -s disconnect <domain>
The problem is that one-time-password may change during the execution of vpn -s connect <domain>. So I was curious whether it's possible to change the script so that it lets me enter the one-time-password after <pin> has been inserted automatically? I've tried it with head -c -1 to remove the last newline char but the input was still finished. Any other solution not based on EOF is acceptable.
bash here-document
bash here-document
edited Nov 25 at 7:48
Cyrus
7,1812835
7,1812835
asked Nov 25 at 7:45
ka3ak
556518
556518
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
You can always do:
printf '<user>n<pin>'
printf 'Enter the one-time password: ' > /dev/tty
IFS= read -r otp < /dev/tty
printf '%sn' "$otp"
| vpn -s connect <domain>
Which prompts for the password after vpn has been started and already fed <user>n<pin>.
It reads the password and prints the prompts on the tty device, alternatively you could read from stdin (remove the < /dev/tty) and print the prompt on stderr (replace > /dev/tty with >&2).
If using zsh instead of bash, you could simplify that to:
printf '<user>n<pin>'
IFS= read -rse '?Enter the one-time password: '
| vpn -s connect <domain>
-sto suppress the terminalecho(that one also supported bybash), preferable to input passwords.-eto echo the entered text on stdout instead of storing into a variable?prompt, prompt string sent on stderr, same syntax asksh.bashhas a-poption for that.
Something goes wrong here. The output starts with Enter the one-time password: Cisco AnyConnect Secure Mobility Client (version 4.6.02074) . Copyright (c) 2004 - 2018 Cisco Systems, Inc. All Rights Reserved. ... As you can see I have no chance to enter something
– ka3ak
Nov 25 at 8:17
@ka3ak well yes. both parts of the pipeline are run together so you can enter the password after vpn has started as you asked. You can add asleep 1before the prompt if you want it to be printed after vpn's initialisation message.
– Stéphane Chazelas
Nov 25 at 8:23
add a comment |
up vote
0
down vote
You could probably do something similar to this -
$: head -1 <<!
hello, $(head -1<$(tty))!
!
But I don't recommend it for several reasons.
Only slightly better -
$: head -1 <<!
hello, $(read -rs pw <$(tty); echo "$pw" )!
!
hello, world!
Still, it's what you asked.
New contributor
Paul Hodges is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
You can always do:
printf '<user>n<pin>'
printf 'Enter the one-time password: ' > /dev/tty
IFS= read -r otp < /dev/tty
printf '%sn' "$otp"
| vpn -s connect <domain>
Which prompts for the password after vpn has been started and already fed <user>n<pin>.
It reads the password and prints the prompts on the tty device, alternatively you could read from stdin (remove the < /dev/tty) and print the prompt on stderr (replace > /dev/tty with >&2).
If using zsh instead of bash, you could simplify that to:
printf '<user>n<pin>'
IFS= read -rse '?Enter the one-time password: '
| vpn -s connect <domain>
-sto suppress the terminalecho(that one also supported bybash), preferable to input passwords.-eto echo the entered text on stdout instead of storing into a variable?prompt, prompt string sent on stderr, same syntax asksh.bashhas a-poption for that.
Something goes wrong here. The output starts with Enter the one-time password: Cisco AnyConnect Secure Mobility Client (version 4.6.02074) . Copyright (c) 2004 - 2018 Cisco Systems, Inc. All Rights Reserved. ... As you can see I have no chance to enter something
– ka3ak
Nov 25 at 8:17
@ka3ak well yes. both parts of the pipeline are run together so you can enter the password after vpn has started as you asked. You can add asleep 1before the prompt if you want it to be printed after vpn's initialisation message.
– Stéphane Chazelas
Nov 25 at 8:23
add a comment |
up vote
0
down vote
You can always do:
printf '<user>n<pin>'
printf 'Enter the one-time password: ' > /dev/tty
IFS= read -r otp < /dev/tty
printf '%sn' "$otp"
| vpn -s connect <domain>
Which prompts for the password after vpn has been started and already fed <user>n<pin>.
It reads the password and prints the prompts on the tty device, alternatively you could read from stdin (remove the < /dev/tty) and print the prompt on stderr (replace > /dev/tty with >&2).
If using zsh instead of bash, you could simplify that to:
printf '<user>n<pin>'
IFS= read -rse '?Enter the one-time password: '
| vpn -s connect <domain>
-sto suppress the terminalecho(that one also supported bybash), preferable to input passwords.-eto echo the entered text on stdout instead of storing into a variable?prompt, prompt string sent on stderr, same syntax asksh.bashhas a-poption for that.
Something goes wrong here. The output starts with Enter the one-time password: Cisco AnyConnect Secure Mobility Client (version 4.6.02074) . Copyright (c) 2004 - 2018 Cisco Systems, Inc. All Rights Reserved. ... As you can see I have no chance to enter something
– ka3ak
Nov 25 at 8:17
@ka3ak well yes. both parts of the pipeline are run together so you can enter the password after vpn has started as you asked. You can add asleep 1before the prompt if you want it to be printed after vpn's initialisation message.
– Stéphane Chazelas
Nov 25 at 8:23
add a comment |
up vote
0
down vote
up vote
0
down vote
You can always do:
printf '<user>n<pin>'
printf 'Enter the one-time password: ' > /dev/tty
IFS= read -r otp < /dev/tty
printf '%sn' "$otp"
| vpn -s connect <domain>
Which prompts for the password after vpn has been started and already fed <user>n<pin>.
It reads the password and prints the prompts on the tty device, alternatively you could read from stdin (remove the < /dev/tty) and print the prompt on stderr (replace > /dev/tty with >&2).
If using zsh instead of bash, you could simplify that to:
printf '<user>n<pin>'
IFS= read -rse '?Enter the one-time password: '
| vpn -s connect <domain>
-sto suppress the terminalecho(that one also supported bybash), preferable to input passwords.-eto echo the entered text on stdout instead of storing into a variable?prompt, prompt string sent on stderr, same syntax asksh.bashhas a-poption for that.
You can always do:
printf '<user>n<pin>'
printf 'Enter the one-time password: ' > /dev/tty
IFS= read -r otp < /dev/tty
printf '%sn' "$otp"
| vpn -s connect <domain>
Which prompts for the password after vpn has been started and already fed <user>n<pin>.
It reads the password and prints the prompts on the tty device, alternatively you could read from stdin (remove the < /dev/tty) and print the prompt on stderr (replace > /dev/tty with >&2).
If using zsh instead of bash, you could simplify that to:
printf '<user>n<pin>'
IFS= read -rse '?Enter the one-time password: '
| vpn -s connect <domain>
-sto suppress the terminalecho(that one also supported bybash), preferable to input passwords.-eto echo the entered text on stdout instead of storing into a variable?prompt, prompt string sent on stderr, same syntax asksh.bashhas a-poption for that.
edited Nov 25 at 8:10
answered Nov 25 at 8:00
Stéphane Chazelas
295k54559902
295k54559902
Something goes wrong here. The output starts with Enter the one-time password: Cisco AnyConnect Secure Mobility Client (version 4.6.02074) . Copyright (c) 2004 - 2018 Cisco Systems, Inc. All Rights Reserved. ... As you can see I have no chance to enter something
– ka3ak
Nov 25 at 8:17
@ka3ak well yes. both parts of the pipeline are run together so you can enter the password after vpn has started as you asked. You can add asleep 1before the prompt if you want it to be printed after vpn's initialisation message.
– Stéphane Chazelas
Nov 25 at 8:23
add a comment |
Something goes wrong here. The output starts with Enter the one-time password: Cisco AnyConnect Secure Mobility Client (version 4.6.02074) . Copyright (c) 2004 - 2018 Cisco Systems, Inc. All Rights Reserved. ... As you can see I have no chance to enter something
– ka3ak
Nov 25 at 8:17
@ka3ak well yes. both parts of the pipeline are run together so you can enter the password after vpn has started as you asked. You can add asleep 1before the prompt if you want it to be printed after vpn's initialisation message.
– Stéphane Chazelas
Nov 25 at 8:23
Something goes wrong here. The output starts with Enter the one-time password: Cisco AnyConnect Secure Mobility Client (version 4.6.02074) . Copyright (c) 2004 - 2018 Cisco Systems, Inc. All Rights Reserved. ... As you can see I have no chance to enter something
– ka3ak
Nov 25 at 8:17
Something goes wrong here. The output starts with Enter the one-time password: Cisco AnyConnect Secure Mobility Client (version 4.6.02074) . Copyright (c) 2004 - 2018 Cisco Systems, Inc. All Rights Reserved. ... As you can see I have no chance to enter something
– ka3ak
Nov 25 at 8:17
@ka3ak well yes. both parts of the pipeline are run together so you can enter the password after vpn has started as you asked. You can add a
sleep 1 before the prompt if you want it to be printed after vpn's initialisation message.– Stéphane Chazelas
Nov 25 at 8:23
@ka3ak well yes. both parts of the pipeline are run together so you can enter the password after vpn has started as you asked. You can add a
sleep 1 before the prompt if you want it to be printed after vpn's initialisation message.– Stéphane Chazelas
Nov 25 at 8:23
add a comment |
up vote
0
down vote
You could probably do something similar to this -
$: head -1 <<!
hello, $(head -1<$(tty))!
!
But I don't recommend it for several reasons.
Only slightly better -
$: head -1 <<!
hello, $(read -rs pw <$(tty); echo "$pw" )!
!
hello, world!
Still, it's what you asked.
New contributor
Paul Hodges is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
0
down vote
You could probably do something similar to this -
$: head -1 <<!
hello, $(head -1<$(tty))!
!
But I don't recommend it for several reasons.
Only slightly better -
$: head -1 <<!
hello, $(read -rs pw <$(tty); echo "$pw" )!
!
hello, world!
Still, it's what you asked.
New contributor
Paul Hodges is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
0
down vote
up vote
0
down vote
You could probably do something similar to this -
$: head -1 <<!
hello, $(head -1<$(tty))!
!
But I don't recommend it for several reasons.
Only slightly better -
$: head -1 <<!
hello, $(read -rs pw <$(tty); echo "$pw" )!
!
hello, world!
Still, it's what you asked.
New contributor
Paul Hodges is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
You could probably do something similar to this -
$: head -1 <<!
hello, $(head -1<$(tty))!
!
But I don't recommend it for several reasons.
Only slightly better -
$: head -1 <<!
hello, $(read -rs pw <$(tty); echo "$pw" )!
!
hello, world!
Still, it's what you asked.
New contributor
Paul Hodges is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Paul Hodges is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered Nov 26 at 19:05
Paul Hodges
1563
1563
New contributor
Paul Hodges is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Paul Hodges is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Paul Hodges is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f483995%2fcan-i-use-eof-but-let-user-to-complete-the-input%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown