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.
bash shell input terminal io-redirection
|
show 5 more comments
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.
bash shell input terminal io-redirection
 
 
 
 
 
 
 wouldn't it be possible if the inputs are provided as- argumentsto 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- vpnis 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- vpncommand resets the standard input before actually attempting to prompt for- VPN IPetc. . . 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/ttyis the current device (major 5, minor 0), and- /dev/ttyNis a specific device. (See kernel.org/doc/html/latest/admin-guide/devices.html)
 – William Pursell
 Nov 22 at 16:56
 
 
 
 
 
|
show 5 more comments
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.
bash shell input terminal io-redirection
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
bash shell input terminal io-redirection
asked Nov 22 at 16:24
Priyank Palod
335
335
 
 
 
 
 
 
 wouldn't it be possible if the inputs are provided as- argumentsto 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- vpnis 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- vpncommand resets the standard input before actually attempting to prompt for- VPN IPetc. . . 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/ttyis the current device (major 5, minor 0), and- /dev/ttyNis a specific device. (See kernel.org/doc/html/latest/admin-guide/devices.html)
 – William Pursell
 Nov 22 at 16:56
 
 
 
 
 
|
show 5 more comments
 
 
 
 
 
 
 wouldn't it be possible if the inputs are provided as- argumentsto 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- vpnis 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- vpncommand resets the standard input before actually attempting to prompt for- VPN IPetc. . . 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/ttyis the current device (major 5, minor 0), and- /dev/ttyNis 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
|
show 5 more comments
                                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
add a comment |
                                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
add a comment |
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
add a comment |
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
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
edited Nov 22 at 18:59
answered Nov 22 at 18:51


Ljm Dullaart
1,7661616
1,7661616
add a comment |
add a comment |
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.
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%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
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
wouldn't it be possible if the inputs are provided as
argumentsto 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
vpnis 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
vpncommand resets the standard input before actually attempting to prompt forVPN IPetc. . . 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/ttyis the current device (major 5, minor 0), and/dev/ttyNis a specific device. (See kernel.org/doc/html/latest/admin-guide/devices.html)– William Pursell
Nov 22 at 16:56