Why does this command not take input from file inspite of rediection?











up vote
1
down vote

favorite












On executing, the cisco anyconnect VPN client takes the VPN IP, password, and some other inputs from the terminal. However, instead of typing it every time, I wrote down the values in a file and tried to redirect the file into the vpn client command.



/opt/cisco/anyconnect/bin/vpn < vpndetails.txt


However, it seems that the command ignores the file redirection and still prompts for input. How is it possible? Does the code read from some other file-descriptor (not 0) and still reads it from the terminal? Is it possible?



Note: I know it isn't a good practice to store your passwords in a file, but I don't care for now.










share|improve this question






















  • wouldn't it be possible if the inputs are provided as arguments to the command? i guess it would make things easy..
    – User123
    Nov 22 at 16:30










  • When a process is started by an interactive shell, that process inherits its stdin from the tty. Your redirection changes the behavior so that the process' stdin is the file. However, the tty still exists, and it looks like vpn is simply reading from it directly, rather than reading from stdin. For a simple example, write a script that reads from /dev/tty
    – William Pursell
    Nov 22 at 16:31










  • One possibility is that the vpn command resets the standard input before actually attempting to prompt for VPN IP etc. . . So, then you should try something different, like (sleep 1 ; printf "192.168.56.2n" ; sleep 1; printf "asecretn" ; ...) | /opt/cisco/anyconnect/bin/vpn
    – Jay jargot
    Nov 22 at 16:34








  • 1




    @PriyankPalod There are multiple terminals, but /dev/tty (no trailing number) is typically the controlling terminal for the current process.
    – chepner
    Nov 22 at 16:53






  • 1




    It would do that to ensure that passwords are being entered interactively, to prevent the security weakness introduced by people trying to put passwords in regular files. Yes, there are multiple ttys. /dev/tty is the current device (major 5, minor 0), and /dev/ttyN is a specific device. (See kernel.org/doc/html/latest/admin-guide/devices.html)
    – William Pursell
    Nov 22 at 16:56

















up vote
1
down vote

favorite












On executing, the cisco anyconnect VPN client takes the VPN IP, password, and some other inputs from the terminal. However, instead of typing it every time, I wrote down the values in a file and tried to redirect the file into the vpn client command.



/opt/cisco/anyconnect/bin/vpn < vpndetails.txt


However, it seems that the command ignores the file redirection and still prompts for input. How is it possible? Does the code read from some other file-descriptor (not 0) and still reads it from the terminal? Is it possible?



Note: I know it isn't a good practice to store your passwords in a file, but I don't care for now.










share|improve this question






















  • wouldn't it be possible if the inputs are provided as arguments to the command? i guess it would make things easy..
    – User123
    Nov 22 at 16:30










  • When a process is started by an interactive shell, that process inherits its stdin from the tty. Your redirection changes the behavior so that the process' stdin is the file. However, the tty still exists, and it looks like vpn is simply reading from it directly, rather than reading from stdin. For a simple example, write a script that reads from /dev/tty
    – William Pursell
    Nov 22 at 16:31










  • One possibility is that the vpn command resets the standard input before actually attempting to prompt for VPN IP etc. . . So, then you should try something different, like (sleep 1 ; printf "192.168.56.2n" ; sleep 1; printf "asecretn" ; ...) | /opt/cisco/anyconnect/bin/vpn
    – Jay jargot
    Nov 22 at 16:34








  • 1




    @PriyankPalod There are multiple terminals, but /dev/tty (no trailing number) is typically the controlling terminal for the current process.
    – chepner
    Nov 22 at 16:53






  • 1




    It would do that to ensure that passwords are being entered interactively, to prevent the security weakness introduced by people trying to put passwords in regular files. Yes, there are multiple ttys. /dev/tty is the current device (major 5, minor 0), and /dev/ttyN is a specific device. (See kernel.org/doc/html/latest/admin-guide/devices.html)
    – William Pursell
    Nov 22 at 16:56















up vote
1
down vote

favorite









up vote
1
down vote

favorite











On executing, the cisco anyconnect VPN client takes the VPN IP, password, and some other inputs from the terminal. However, instead of typing it every time, I wrote down the values in a file and tried to redirect the file into the vpn client command.



/opt/cisco/anyconnect/bin/vpn < vpndetails.txt


However, it seems that the command ignores the file redirection and still prompts for input. How is it possible? Does the code read from some other file-descriptor (not 0) and still reads it from the terminal? Is it possible?



Note: I know it isn't a good practice to store your passwords in a file, but I don't care for now.










share|improve this question













On executing, the cisco anyconnect VPN client takes the VPN IP, password, and some other inputs from the terminal. However, instead of typing it every time, I wrote down the values in a file and tried to redirect the file into the vpn client command.



/opt/cisco/anyconnect/bin/vpn < vpndetails.txt


However, it seems that the command ignores the file redirection and still prompts for input. How is it possible? Does the code read from some other file-descriptor (not 0) and still reads it from the terminal? Is it possible?



Note: I know it isn't a good practice to store your passwords in a file, but I don't care for now.







bash shell input terminal io-redirection






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 at 16:24









Priyank Palod

335




335












  • wouldn't it be possible if the inputs are provided as arguments to the command? i guess it would make things easy..
    – User123
    Nov 22 at 16:30










  • When a process is started by an interactive shell, that process inherits its stdin from the tty. Your redirection changes the behavior so that the process' stdin is the file. However, the tty still exists, and it looks like vpn is simply reading from it directly, rather than reading from stdin. For a simple example, write a script that reads from /dev/tty
    – William Pursell
    Nov 22 at 16:31










  • One possibility is that the vpn command resets the standard input before actually attempting to prompt for VPN IP etc. . . So, then you should try something different, like (sleep 1 ; printf "192.168.56.2n" ; sleep 1; printf "asecretn" ; ...) | /opt/cisco/anyconnect/bin/vpn
    – Jay jargot
    Nov 22 at 16:34








  • 1




    @PriyankPalod There are multiple terminals, but /dev/tty (no trailing number) is typically the controlling terminal for the current process.
    – chepner
    Nov 22 at 16:53






  • 1




    It would do that to ensure that passwords are being entered interactively, to prevent the security weakness introduced by people trying to put passwords in regular files. Yes, there are multiple ttys. /dev/tty is the current device (major 5, minor 0), and /dev/ttyN is a specific device. (See kernel.org/doc/html/latest/admin-guide/devices.html)
    – William Pursell
    Nov 22 at 16:56




















  • wouldn't it be possible if the inputs are provided as arguments to the command? i guess it would make things easy..
    – User123
    Nov 22 at 16:30










  • When a process is started by an interactive shell, that process inherits its stdin from the tty. Your redirection changes the behavior so that the process' stdin is the file. However, the tty still exists, and it looks like vpn is simply reading from it directly, rather than reading from stdin. For a simple example, write a script that reads from /dev/tty
    – William Pursell
    Nov 22 at 16:31










  • One possibility is that the vpn command resets the standard input before actually attempting to prompt for VPN IP etc. . . So, then you should try something different, like (sleep 1 ; printf "192.168.56.2n" ; sleep 1; printf "asecretn" ; ...) | /opt/cisco/anyconnect/bin/vpn
    – Jay jargot
    Nov 22 at 16:34








  • 1




    @PriyankPalod There are multiple terminals, but /dev/tty (no trailing number) is typically the controlling terminal for the current process.
    – chepner
    Nov 22 at 16:53






  • 1




    It would do that to ensure that passwords are being entered interactively, to prevent the security weakness introduced by people trying to put passwords in regular files. Yes, there are multiple ttys. /dev/tty is the current device (major 5, minor 0), and /dev/ttyN is a specific device. (See kernel.org/doc/html/latest/admin-guide/devices.html)
    – William Pursell
    Nov 22 at 16:56


















wouldn't it be possible if the inputs are provided as arguments to the command? i guess it would make things easy..
– User123
Nov 22 at 16:30




wouldn't it be possible if the inputs are provided as arguments to the command? i guess it would make things easy..
– User123
Nov 22 at 16:30












When a process is started by an interactive shell, that process inherits its stdin from the tty. Your redirection changes the behavior so that the process' stdin is the file. However, the tty still exists, and it looks like vpn is simply reading from it directly, rather than reading from stdin. For a simple example, write a script that reads from /dev/tty
– William Pursell
Nov 22 at 16:31




When a process is started by an interactive shell, that process inherits its stdin from the tty. Your redirection changes the behavior so that the process' stdin is the file. However, the tty still exists, and it looks like vpn is simply reading from it directly, rather than reading from stdin. For a simple example, write a script that reads from /dev/tty
– William Pursell
Nov 22 at 16:31












One possibility is that the vpn command resets the standard input before actually attempting to prompt for VPN IP etc. . . So, then you should try something different, like (sleep 1 ; printf "192.168.56.2n" ; sleep 1; printf "asecretn" ; ...) | /opt/cisco/anyconnect/bin/vpn
– Jay jargot
Nov 22 at 16:34






One possibility is that the vpn command resets the standard input before actually attempting to prompt for VPN IP etc. . . So, then you should try something different, like (sleep 1 ; printf "192.168.56.2n" ; sleep 1; printf "asecretn" ; ...) | /opt/cisco/anyconnect/bin/vpn
– Jay jargot
Nov 22 at 16:34






1




1




@PriyankPalod There are multiple terminals, but /dev/tty (no trailing number) is typically the controlling terminal for the current process.
– chepner
Nov 22 at 16:53




@PriyankPalod There are multiple terminals, but /dev/tty (no trailing number) is typically the controlling terminal for the current process.
– chepner
Nov 22 at 16:53




1




1




It would do that to ensure that passwords are being entered interactively, to prevent the security weakness introduced by people trying to put passwords in regular files. Yes, there are multiple ttys. /dev/tty is the current device (major 5, minor 0), and /dev/ttyN is a specific device. (See kernel.org/doc/html/latest/admin-guide/devices.html)
– William Pursell
Nov 22 at 16:56






It would do that to ensure that passwords are being entered interactively, to prevent the security weakness introduced by people trying to put passwords in regular files. Yes, there are multiple ttys. /dev/tty is the current device (major 5, minor 0), and /dev/ttyN is a specific device. (See kernel.org/doc/html/latest/admin-guide/devices.html)
– William Pursell
Nov 22 at 16:56














1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










The question "Is it possible" has the answer "yes".



The code for the anyconnect vpn probably reads /dev/tty, as explained in the comments by Chepner e.a.As a fun exercise, try this script:



#! /bin/sh 

read -p "STDIN> " a
read -p "TERMINAL> " b < /dev/tty
read -p "STDIN> " c

echo "Read $a and $c from stdio and $b from the terminal"


and, for example, ls / | bash this_script.sh.



However, if you wish to use Cisco Autoconnect without passwords, you should investigate the Always On with Trusted Network detection feature and user certificates.



Writing to /dev/tty in the hope that it will be picked-up by the script does not work:



ljm@verlaine[tmp]$ ls | bash test.sh &
[3] 10558
ljm@verlaine[tmp]$ echo 'plop' > /dev/tty
plop

[3]+ Stopped ls | bash test.sh
ljm@verlaine[tmp]$ fg
ls | bash test.sh
(a loose enter is given)
Read a_file and b_file from stdio and from the terminal





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    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: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    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%2fstackoverflow.com%2fquestions%2f53434963%2fwhy-does-this-command-not-take-input-from-file-inspite-of-rediection%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote



    accepted










    The question "Is it possible" has the answer "yes".



    The code for the anyconnect vpn probably reads /dev/tty, as explained in the comments by Chepner e.a.As a fun exercise, try this script:



    #! /bin/sh 

    read -p "STDIN> " a
    read -p "TERMINAL> " b < /dev/tty
    read -p "STDIN> " c

    echo "Read $a and $c from stdio and $b from the terminal"


    and, for example, ls / | bash this_script.sh.



    However, if you wish to use Cisco Autoconnect without passwords, you should investigate the Always On with Trusted Network detection feature and user certificates.



    Writing to /dev/tty in the hope that it will be picked-up by the script does not work:



    ljm@verlaine[tmp]$ ls | bash test.sh &
    [3] 10558
    ljm@verlaine[tmp]$ echo 'plop' > /dev/tty
    plop

    [3]+ Stopped ls | bash test.sh
    ljm@verlaine[tmp]$ fg
    ls | bash test.sh
    (a loose enter is given)
    Read a_file and b_file from stdio and from the terminal





    share|improve this answer



























      up vote
      1
      down vote



      accepted










      The question "Is it possible" has the answer "yes".



      The code for the anyconnect vpn probably reads /dev/tty, as explained in the comments by Chepner e.a.As a fun exercise, try this script:



      #! /bin/sh 

      read -p "STDIN> " a
      read -p "TERMINAL> " b < /dev/tty
      read -p "STDIN> " c

      echo "Read $a and $c from stdio and $b from the terminal"


      and, for example, ls / | bash this_script.sh.



      However, if you wish to use Cisco Autoconnect without passwords, you should investigate the Always On with Trusted Network detection feature and user certificates.



      Writing to /dev/tty in the hope that it will be picked-up by the script does not work:



      ljm@verlaine[tmp]$ ls | bash test.sh &
      [3] 10558
      ljm@verlaine[tmp]$ echo 'plop' > /dev/tty
      plop

      [3]+ Stopped ls | bash test.sh
      ljm@verlaine[tmp]$ fg
      ls | bash test.sh
      (a loose enter is given)
      Read a_file and b_file from stdio and from the terminal





      share|improve this answer

























        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted






        The question "Is it possible" has the answer "yes".



        The code for the anyconnect vpn probably reads /dev/tty, as explained in the comments by Chepner e.a.As a fun exercise, try this script:



        #! /bin/sh 

        read -p "STDIN> " a
        read -p "TERMINAL> " b < /dev/tty
        read -p "STDIN> " c

        echo "Read $a and $c from stdio and $b from the terminal"


        and, for example, ls / | bash this_script.sh.



        However, if you wish to use Cisco Autoconnect without passwords, you should investigate the Always On with Trusted Network detection feature and user certificates.



        Writing to /dev/tty in the hope that it will be picked-up by the script does not work:



        ljm@verlaine[tmp]$ ls | bash test.sh &
        [3] 10558
        ljm@verlaine[tmp]$ echo 'plop' > /dev/tty
        plop

        [3]+ Stopped ls | bash test.sh
        ljm@verlaine[tmp]$ fg
        ls | bash test.sh
        (a loose enter is given)
        Read a_file and b_file from stdio and from the terminal





        share|improve this answer














        The question "Is it possible" has the answer "yes".



        The code for the anyconnect vpn probably reads /dev/tty, as explained in the comments by Chepner e.a.As a fun exercise, try this script:



        #! /bin/sh 

        read -p "STDIN> " a
        read -p "TERMINAL> " b < /dev/tty
        read -p "STDIN> " c

        echo "Read $a and $c from stdio and $b from the terminal"


        and, for example, ls / | bash this_script.sh.



        However, if you wish to use Cisco Autoconnect without passwords, you should investigate the Always On with Trusted Network detection feature and user certificates.



        Writing to /dev/tty in the hope that it will be picked-up by the script does not work:



        ljm@verlaine[tmp]$ ls | bash test.sh &
        [3] 10558
        ljm@verlaine[tmp]$ echo 'plop' > /dev/tty
        plop

        [3]+ Stopped ls | bash test.sh
        ljm@verlaine[tmp]$ fg
        ls | bash test.sh
        (a loose enter is given)
        Read a_file and b_file from stdio and from the terminal






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 22 at 18:59

























        answered Nov 22 at 18:51









        Ljm Dullaart

        1,7661616




        1,7661616






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • 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%2fstackoverflow.com%2fquestions%2f53434963%2fwhy-does-this-command-not-take-input-from-file-inspite-of-rediection%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

            Trompette piccolo

            Slow SSRS Report in dynamic grouping and multiple parameters

            Simon Yates (cyclisme)