Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

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

share|improve this answer

In more detail, this is an extract of the script:

#!/usr/bin/expect -f

set password [lrange $argv 1 1]
set timeout -1
match_max 100000
spawn /usr/sbin/vpnc --local-port 0 vpnc.conf
expect {        
        "Enter password for" {
                send -- "$password\r"
send -- "\r"

Then you can run it like

cat .passwd | xargs -n 1 expect-vpnc.exp

And your .passwd files contains only one line with the password

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.