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

The name of the pictureThe name of the pictureThe name of the pictureClash 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.










share|improve this question



























    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.










    share|improve this question

























      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.










      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 25 at 7:48









      Cyrus

      7,1812835




      7,1812835










      asked Nov 25 at 7:45









      ka3ak

      556518




      556518




















          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>



          • -s to suppress the terminal echo (that one also supported by bash), preferable to input passwords.


          • -e to echo the entered text on stdout instead of storing into a variable


          • ?prompt, prompt string sent on stderr, same syntax as ksh. bash has a -p option for that.





          share|improve this answer






















          • 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

















          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.






          share|improve this answer








          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.

















            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "106"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            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

























            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>



            • -s to suppress the terminal echo (that one also supported by bash), preferable to input passwords.


            • -e to echo the entered text on stdout instead of storing into a variable


            • ?prompt, prompt string sent on stderr, same syntax as ksh. bash has a -p option for that.





            share|improve this answer






















            • 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














            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>



            • -s to suppress the terminal echo (that one also supported by bash), preferable to input passwords.


            • -e to echo the entered text on stdout instead of storing into a variable


            • ?prompt, prompt string sent on stderr, same syntax as ksh. bash has a -p option for that.





            share|improve this answer






















            • 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












            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>



            • -s to suppress the terminal echo (that one also supported by bash), preferable to input passwords.


            • -e to echo the entered text on stdout instead of storing into a variable


            • ?prompt, prompt string sent on stderr, same syntax as ksh. bash has a -p option for that.





            share|improve this answer














            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>



            • -s to suppress the terminal echo (that one also supported by bash), preferable to input passwords.


            • -e to echo the entered text on stdout instead of storing into a variable


            • ?prompt, prompt string sent on stderr, same syntax as ksh. bash has a -p option for that.






            share|improve this answer














            share|improve this answer



            share|improve this answer








            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 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
















            • 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















            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












            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.






            share|improve this answer








            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.





















              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.






              share|improve this answer








              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.



















                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.






                share|improve this answer








                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.







                share|improve this answer








                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.









                share|improve this answer



                share|improve this answer






                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.



























                    draft saved

                    draft discarded
















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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






                    Popular posts from this blog

                    Peggy Mitchell

                    Palaiologos

                    The Forum (Inglewood, California)