Bash – Script to run vpnc, and enter password

bashscripting

My vpnc connection is breaking quite often, and my friend created a script, which runs vpnc, and runs another "guard" script, which in turn checks every minute if vpnc is still connected, and connects it if it is not.

The difference between me and my friend is that he has static password, and I use small device to generate different password every time. It's not a problem for guard script to run zenity to display small window to enter password into, the problem is how to pass this password to vpnc?

I tried here-document, like this:

PASS=`zenity --entry --title="VPN Password" --text="Enter your password:"`
sudo vpnc $SCRIPTPATH/vpnc.conf<<<$PASS

But this doesn't work. Vpnc keeps asking for password on command-line. How can I feed it with password in script?

Best Answer

You could use 'expect' to wait for the "Password:" prompt and feed in $PASS.

http://linux.die.net/man/1/expect