0

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?

amorfis
  • 737
  • 2
  • 14
  • 31

2 Answers2

1

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

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

MrTuttle
  • 1,176
  • 5
  • 5
1

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"
interact

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

ghm1014
  • 944
  • 1
  • 5
  • 14