LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-16-2007, 09:09 PM   #1
oopicwow
LQ Newbie
 
Registered: Dec 2007
Posts: 3

Rep: Reputation: 0
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!
 
Old 12-17-2007, 01:16 AM   #2
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
Try the 'expect' utility; it's designed to do that sort of thing. eg http://www.ibm.com/developerworks/linux/library/l-sc1/
 
Old 12-17-2007, 01:35 AM   #3
geoff_f
Member
 
Registered: May 2003
Location: Canberra, Australia
Distribution: openSUSE 11.3
Posts: 445

Rep: Reputation: 31
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:
echo "Enter IPSec gateway address:"
You should see a read command following that which puts the answer into a variable. What you need to do is to allocate the answer directly to the variable. For example, if the statements concerning the first question are:
Quote:
echo "Enter IPSec gateway address:"
read IPSec_gateway_address
then comment those lines out and add the direct variable assignment in the following line, like this:
Quote:
# echo "Enter IPSec gateway address:"
# read IPSec_gateway_address
IPSec_gateway_address="192.168.1.15"
The example uses a dummy IP Address and takes a guess at what the variable may be called; naturally, use whatever address is applicable to your system, and whatever variable name your vpnc-connect script uses. Continue on to complete the remainder of the questions, then you should be OK to use the script without user input. I would make sure the script is given strict permissions once the connection information is embedded in it. I would suggest:
Quote:
chmod 700 /usr/sbin/vpnc-connect
(assuming it is located in /usr/sbin on your system).

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.
 
Old 12-17-2007, 03:35 AM   #4
BlisteringSh33p
LQ Newbie
 
Registered: Jun 2006
Location: Virginia
Distribution: Gentoo, Slackware, RHAS, MontaVista, Fedora, Ubuntu
Posts: 4

Rep: Reputation: 0
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}
 
Old 12-17-2007, 06:38 PM   #5
oopicwow
LQ Newbie
 
Registered: Dec 2007
Posts: 3

Original Poster
Rep: Reputation: 0
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.
 
Old 01-15-2008, 02:32 PM   #6
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 231Reputation: 231Reputation: 231
What did you do?

Maybe help others? -- Post your solution.

Last edited by archtoad6; 01-22-2008 at 10:31 AM. Reason: missing word :( :tisk:
 
Old 01-21-2008, 09:02 PM   #7
oopicwow
LQ Newbie
 
Registered: Dec 2007
Posts: 3

Original Poster
Rep: Reputation: 0
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.
 
  


Reply

Tags
expect, vpn, vpnc


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run Bash Script @ login XaViaR Linux - General 5 01-26-2006 11:05 PM
bash login script bunnyknight13 Linux - Newbie 4 09-10-2004 09:02 PM
bash login script seanatis Programming 6 09-06-2004 09:00 AM
Run script at login instead of bash uzi4u Linux - General 2 04-28-2004 03:31 PM
Trying to execute bash script upon login?? mr-d-2003 Linux - Newbie 4 10-30-2003 04:15 PM


All times are GMT -5. The time now is 11:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration