I have a bash script that invokes openconnect, which then turns around and reads 4 lines from stdin. These are (in order): group, password, authentication type, and one-time passcode.
I can programmatically get the values for the first 3, but the one-time passcode changes each time. Is there a way to write a script that can redirect stdin for the first 3 values (printf "%s\n%s\n%s\n" $group $password $auth
) then have the program read the last line (the one-time passcode) as keyboard input?
#!/bin/bash
set -e
type="GROUP_SUBSTITUTED"
pass=`pass password_substituted`
auth="1"
echo -e "$type\n$pass\n$auth" |
sudo openconnect \
-u username_substituted \
-i tun1 \
vpn.substituted.url
In the above script, I pass 3 of the 4 things openconnect
prompts for, but when it prompts for the 4th value (the one-time passcode) it immediately swallows an empty string instead of waiting for keyboard input.