LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 08-25-2011, 04:51 PM   #1
Mouse750
Member
 
Registered: Aug 2011
Distribution: Ubuntu
Posts: 50

Rep: Reputation: Disabled
My First Script.... Some friendly guidance needed.


Long time point and click Micro$#it Windblows user Here. Just Switched to linux (Ubuntu for now) a few months ago. I have to admit at first I hated the idea of using a terminal for anything but now I've come 180.

I am amazed what you can do with it. Now that I am getting better a grip on my basic terminal usage it has dawned on me that you can automate mundane tasks with scripts.

Ok be kind, This is what I have so far...

Code:
#!/bin/

iptables -R wan_Accept 7 -j ACCEPT -d 174.145.14.54 -o eth3
iptables -I lan_Accept 2 -j ACCEPT -d -i eth3
iptables -D reject 2 -j DROP -d -i eth3
cd /etc/confg
openvpn --config New_York.opvn &
sleep 3600
killall openvpn
sleep 5
openvpn --config Los_Angeles.opvn &
sleep 3600
killall openvpn
sleep 5
openvpn --config Chicago.opvn &
sleep 3600
killall openvpn
sleep 5
openvpn --config Phoenix.opvn &
sleep 3600
killall openvpn
sleep 5
openvpn --config Dallas.opvn &
sleep 3600
killall openvpn
sleep 5
openvpn --config Jacksonville.opvn &
sleep 3600
killall openvpn
sleep 5
openvpn --config Indianapolis.opvn &
sleep 3600
killall openvpn
sleep 5
openvpn --config San_Francisco.opvn &
sleep 3600
killall openvpn
sleep 5
First question is: When the script comes to the end, how do I get it to jump to line 7 so that the process can begin again?

--

"Arithmetic is being able to count up to twenty without taking off your shoes."
Mickey Mouse-43rd President of the United States

.

Last edited by Mouse750; 08-25-2011 at 04:57 PM.
 
Old 08-25-2011, 05:19 PM   #2
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,123

Rep: Reputation: 151Reputation: 151
I don't use openvpn so I don't know the effects of what you're doing - but to repeat the sequence of steps, you can wrap it in a loop. There are examples in the Advanced Bash Scripting Guide that should help.
 
Old 08-25-2011, 05:38 PM   #3
Mouse750
Member
 
Registered: Aug 2011
Distribution: Ubuntu
Posts: 50

Original Poster
Rep: Reputation: Disabled
I'm just starting out in scripting. Is there something simpler I could use? Something that doesn't involve complex variables?

If it's this hard just to simply jump to line 7, I'd hate to ask how I could select a random server (LA,Chicago,Dallas,etc)

--

"Arithmetic is being able to count up to twenty without taking off your shoes."
Mickey Mouse-43rd President of the United States

.

Last edited by Mouse750; 08-25-2011 at 05:41 PM.
 
Old 08-25-2011, 05:55 PM   #4
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,123

Rep: Reputation: 151Reputation: 151
It's not that hard to jump to line 7 and it doesn't require complex variables. Try this one instead. Wrap the lines you want to repeat in this:
Code:
while true; do
done
You can add things like break statements and conditions to limit how many times the loop is run.

There are also plenty of random number examples here
 
Old 08-25-2011, 06:26 PM   #5
Mouse750
Member
 
Registered: Aug 2011
Distribution: Ubuntu
Posts: 50

Original Poster
Rep: Reputation: Disabled
I just simply wrapped it like you said and it "works".

I don't know "why" it works. I'll read up on while loops so that maybe I can.

If I can a good understanding of the while loop maybe I'll take a stab at that random server idea.
 
  


Reply


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
script guidance needed kais1 Linux - Newbie 4 12-12-2008 08:13 AM
slackbuild guidance needed mcnalu Slackware 10 05-11-2008 11:07 AM
Adding a second linux. [Guidance needed] Zmyrgel Linux - Newbie 20 01-29-2006 07:49 AM
guidance needed please with java runtime ceborame Ubuntu 2 08-18-2005 01:49 PM
Guidance Needed! LinuxRam Linux - Certification 5 09-07-2004 10:06 PM


All times are GMT -5. The time now is 03:37 AM.

Main Menu
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