LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 02-11-2013, 05:00 AM   #1
suboss87
Member
 
Registered: Dec 2010
Posts: 31

Rep: Reputation: 0
Question shell scripting for my automation process.


Hi,
I need to write a Shell or Perl script for updating iptables on Linux servers, Let me explain the concept.
need to change iptable entries for many our servers located at different countries, so script would be run by any users.
Let us keep it as 3-locations(india, singapore, malaysia) each location has different ip's.

my sample script

Code:
#/bin/bash
india=10.31.0.1
singapore=10.31.0.2
malaysia=10.31.0.3

echo "Enter the country name:"
read country
if [ `$country=$singapore` ]
sed -i /192.168.0.1/$singapore/" /etc/sysconfig/iptables
else
  echo "error"

fi


OUTPUT sample:

./ipchange.sh

Enter the country name: singapore

(after entering the country name, script should verify and update the user required country ip-address. So everything will be embedded with the script)


ipatables updated sucessfully.



Kindly help me out to create a clear script for the same.


Regards,
Subash.

Last edited by suboss87; 02-11-2013 at 05:13 AM.
 
Old 02-11-2013, 07:05 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by suboss87 View Post
I need to write a Shell or Perl script for updating iptables on Linux servers, Let me explain the concept. need to change iptable entries for many our servers located at different countries, so script would be run by any users. Let us keep it as 3-locations(india, singapore, malaysia) each location has different ip's.
Instead of
Code:
if [ `$country=$singapore` ]
you can use a case statement and for example 'getopts' or 'select' to make a selection.

Instead of
Code:
sed -i /192.168.0.1/$singapore/" /etc/sysconfig/iptables
I suggest you use 'mktemp', work on a copy of 'iptables-save' output and make a backup of the current rule set and allow for restoration (at or cron job) on error.

*More importantly you should think about your "country list". What happens if a country gets a second location added? How about addresses? Does each location have only one, fixed IPv4 address? What happens if it changes? If one gets added? These questions don't only apply script-wise but where the script could or should be retrieved from, how you will keep it up to date between locations and who will be responsible for timely modifications.


Code:
function help() { echo "Bash scripting guides:
http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html 
http://www.tldp.org/LDP/Bash-Beginners-Guide/html/index.html 
http://www.gnu.org/software/bash/manual/html_node/index.html
http://www.grymoire.com/Unix/Sh.html
http://www.tldp.org/LDP/abs/html/ 
http://mywiki.wooledge.org/BashFAQ
http://mywiki.wooledge.org/BashPitfalls"; }
 
  


Reply



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
Need help for shell script automation suboss87 Linux - Newbie 1 07-30-2012 08:00 AM
[SOLVED] How to redirect stdin for child process (Linux Shell scripting) ausrasul Programming 4 08-21-2010 09:02 PM
deployment/scripting/automation kevinyeandel Linux - Server 3 02-09-2009 12:51 AM
shell scripting a cpu intensive process on 2 cores dasy2k1 Linux - General 14 07-18-2008 06:20 AM
Bash Scripting - child process affecting parent process mthaddon Linux - General 1 05-02-2004 01:19 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:31 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
Open Source Consulting | Domain Registration