Priyank Palod
Priyank Palod

Reputation: 105

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

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.

Upvotes: 1

Views: 202

Answers (1)

Ljm Dullaart
Ljm Dullaart

Reputation: 4989

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

Upvotes: 1

Related Questions