Bash script for VPN login
Hello, I am trying to write a bash script that will log me into my VPN automatically without me having to enter the same data over when I want to log in.
I found this script but does not seem to do exactly what I need. sudo vpnc-connect read -t 1 incoming I use the "vpnc-connect" but it runs that till it is done then will execute the rest. I was looking for a command like waitfor or something that will look for the follow text and then send the right data based on the incoming text. The questions look like the following: Enter IPSec gateway address: Enter IPSec ID for : Enter IPSec secret for @: Enter username for : Enter password for @: There is probably a program that does this, but I am new to linux and would like to learn how to do this. I have searched the web but unable to find exactly what I need. Thanks! |
Try the 'expect' utility; it's designed to do that sort of thing. eg http://www.ibm.com/developerworks/linux/library/l-sc1/
|
It's likely that vpnc-connect is a bash script that has been designed to gather the required connection information for the vpn client. The best way to achieve what you want is to modify the script to enter the information directly, instead of asking the questions about the connection data. To do this, use a text editor to view the script, and look for the areas where the questions are asked. (You will most likely need to open the text editor as root, as this file is probably a root-owned file.) They should look typically like:
Quote:
Quote:
Quote:
Quote:
An excellent source of information on bash scripts, to help you with understanding how vpnc-connect works is http://www.tldp.org/LDP/abs/html/index.html. |
I know this doesn't directly address your question, but it may solve what you're trying to do.
Do you log in to different VPNs? I only have to use one VPN, and connect with vpnc (http://www.unix-ag.uni-kl.de/~massar/vpnc/). I created /etc/vpnc/default.conf with all of the values stored so I never have to interact with it at all. Contents of /etc/vpnc/default.conf (replace the values in ${}): IPSec gateway ${vpn.example.com} IPSec ID ${IPSecID} IPSec obfuscated secret ${ReallyLongHexCode} Xauth username ${MyName} Xauth password ${MyPlaintextPassword} |
Thanks for the feedback. I will go though your responses. If I can do it in a conf file that will also work. I will only be connecting to one VPN.
Thanks again. |
What did you do?
Maybe help others? -- Post your solution. |
I did exactly what BlisteringSh33p said to do.
"I created /etc/vpnc/default.conf with all of the values stored so I never have to interact with it at all." It did what I needed to do. I just added the vpnc-connect to a script I use to connect to the office so that it is all done in one script. When I close the ssh connection, it will automatically disconnect from the VPN connection. sudo vpnc-connect echo Connecting to work ssh [work server] sudo vpnc-disconnect I found out I really didn't need to do anything fancy. Thanks again. |
All times are GMT -5. The time now is 03:56 AM. |