Shell Script Help

Discussion of programming on Linux, including shell scripting, perl, python, c/c++, mono, java. Whatever tickles your fancy.
Post Reply
mudasir
Captain
Posts: 565
Joined: Tue Oct 17, 2006 5:23 am
Location: Dubai
Contact:

Shell Script Help

Post by mudasir »

AOA,

I am making a script which reads variables from another file. I have accomplished almost all the tasks, only unable to complete one.

What i am doing is that the user will enter IP Address Ranges seperated by space in a variable IP like this

Code: Select all

echo Please Enter IP Ranges Seperated By Space.
read IP
echo -e "IP=$IP" >> /scripts/firewall/firewall.conf
The Input By user can by like 10.10.10 10.10.11 10.10.12
Now the file /scripts/firewall/firewall.conf looks like
IP=10.10.10 10.10.11 10.10.12
Now the file which is retrieving the variables from /scripts/firewall/firewall.conf has code similar to.

Code: Select all

cat /scripts/firewall/firewall.conf | awk '/IP/' | cut -d"=" -f2 
This code is working prefectly.

What i want to do is that count the IP Ranges enter by the user.
In the above example like i enter 3 IP Ranges.

Now what my script should do is that count the IP Ranges and create Variables like IP1 IP2 IP3 and so on till the number of IP Ranges reaches, and each IP Range should have the Range Entered by the User like IP1=10.10.10 IP2=10.10.11 IP3=10.10.12

How can i achieve this.

Looking Forward For Your Replies.
Kind Regards
Mudasir Mirza (RHCE)
(+971)55-1045754
http://www.crystalnetworks.org
http://www.diglinux.com
wacky
Naik
Posts: 94
Joined: Thu Jun 10, 2004 7:42 pm
Location: London, UK

Post by wacky »

Code: Select all

n=1
for i in `cat /scripts/firewall/firewall.conf | awk '/IP/' | cut -d"=" -f2`
do
     echo "IP$n=$i"
     let "n=$n+1"
done
mudasir
Captain
Posts: 565
Joined: Tue Oct 17, 2006 5:23 am
Location: Dubai
Contact:

Post by mudasir »

AOA,

Dear wacky,

I really appreciate it. Thanks alot, you have solved my problem.
Kind Regards
Mudasir Mirza (RHCE)
(+971)55-1045754
http://www.crystalnetworks.org
http://www.diglinux.com
x2oxen
Major General
Posts: 1114
Joined: Wed Aug 22, 2007 3:17 pm
Location: Faisalabad
Contact:

Post by x2oxen »

Mudassir why dont you share you new script as well!
Muhammad Usman
+92-321-6640501
Chemonics International
http://usmanpk.com
mudasir
Captain
Posts: 565
Joined: Tue Oct 17, 2006 5:23 am
Location: Dubai
Contact:

Post by mudasir »

AOA,

Dear x2oxen,

The script is in testing process right now, as soon the testing is complete, i will share the script with LP Members.

Its basically a FIREWALL script but its a bit more user friendly.

It has a ./install script as well, which will install the firewall.
Kind Regards
Mudasir Mirza (RHCE)
(+971)55-1045754
http://www.crystalnetworks.org
http://www.diglinux.com
mudasir
Captain
Posts: 565
Joined: Tue Oct 17, 2006 5:23 am
Location: Dubai
Contact:

Post by mudasir »

AOA,

Dear LP Members,

I have made a Firewall Script. Download the Firewall Script from

http://www.mediafire.com/?4milupsy0tm

Then follow these Steps.
Before doing any thing Read the ReadMe file.

1. After Downloading untar the file by "tar -xvzf firewall.tar.gz"
2. Then goto the Firewall Directory "cd firewall"
3. Then run the install script "./install"
4. Enter All the Things Asked by the Install Script.
Please Dont run the Install Script again and again, If you miss something, Please Read the ReadMe file.

This script is Still a Beta Version, under testing..
Kind Regards
Mudasir Mirza (RHCE)
(+971)55-1045754
http://www.crystalnetworks.org
http://www.diglinux.com
x2oxen
Major General
Posts: 1114
Joined: Wed Aug 22, 2007 3:17 pm
Location: Faisalabad
Contact:

Post by x2oxen »

nice work!
Muhammad Usman
+92-321-6640501
Chemonics International
http://usmanpk.com
mudasir
Captain
Posts: 565
Joined: Tue Oct 17, 2006 5:23 am
Location: Dubai
Contact:

Post by mudasir »

AOA,

Thank you Usman.
Kind Regards
Mudasir Mirza (RHCE)
(+971)55-1045754
http://www.crystalnetworks.org
http://www.diglinux.com
Post Reply