I need to send some credentials defined in a file to a vpn connection command which is waiting for username and password to be entered when executed. There is a similar requirement to my question Automatically enter input in command line.
The following solution provided does work for me too:
printf 'username\npassword\n' | /usr/sbin/openconnect -i vpn0 ...
(executed inside a shell script). But I need to pass the credentials contained in a file (env_properties
) and loaded as environment variables. I'm loading the file content using the following command:
[ -f env_properties] && . env_properties
The content looks as follows
export VPN_USERNAME=myUsername
export VPN_PASSWORD=myPassword
However, such a construct doesn't work anymore:
printf "${VPN_USERNAME}\n${VPN_PASSWORD}\n" | /usr/sbin/openconnect -i vpn0 ...
It seems that the input isn't recognized correctly for whatever reason. And neither this command
printf "/usr/sbin/openconnect -i vpn0 ... < env_properties
with a modified file content containing only plain username and password, each in a new line. Same applies to the here document solution.
Any ideas?