LinuxQuestions.org
Help answer threads with 0 replies.
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 11-18-2005, 11:01 PM   #1
flagg0204
LQ Newbie
 
Registered: Dec 2004
Posts: 3

Rep: Reputation: 0
Bash scripting question


I am working on a script to help me generate configs for all of the various markets I am responsible for. In each market we have routers, switchs, servers and various other equipment. Rather than creating all of these by hand (over 30 markets with roughly 15 devices per market) I am writing a script. All have common IP's except for the network id. I two made a templates
Which has the IP's of the device.

Code:
ip-template
---------------------------------------
NTEL-DNS	.5
INTEL-DHCP	.6
INTEL-AP	.7
INTEL-ISP	.8
INTEL-BACKUP	.9
And desktop.template which is a generic "Gnome Icon" template that will get values plugged into it.

Code:
desktop.template
---------------------------------------------
[Desktop Entry]
Version=1.0
Encoding=UTF-8
Name=#NAME#
Type=Application
Exec=Eterm -O --shade 30 -f white --buttonbar 0 --title #NAME# --exec ssh #USER#@#IP# #NAME#
TryExec=
Icon=/usr/share/pixmaps/gnome-eterm.png
X-GNOME-DocPath=
Terminal=false
Name[en]=#NAME#
GenericName[en]=
Comment[en]=

Code:
#!/bin/bash

LOGIN="root"
WORKDIR="/home/xxxx/Desktop/Markets"
TEMPLATE=desktop.template
IPTEMPLATE=ip-template
BLDTEMP=/tmp

echo -n "Enter city name: "
read city
echo -n "Enter state: "
read state
echo -n "Enter 3 digit market code: "
read  mkt
echo -n "Enter IP Network Address: "
read tempip
baseip=`echo $tempip | cut -d. -f1-3`

complist=`cat $IPTEMPLATE | awk -F"\t" '{print $1}'`
IPLIST=`cat $IPTEMPLATE | awk -F"\t" '{print $2}'`

mkdir $WORKDIR/$city\,$state

for file in $complist;
do 
touch $WORKDIR/$city\,$state/$mkt-POP-$file.tmp
	sed -e s/#NAME#/$mkt-POP-$file/g -e s/#USER#/$LOGIN/g  $TEMPLATE >$WORKDIR/$city\,$state/$mkt-POP-$file.tmp
done
As you can see $complist holds the server names, and IPLIST contains the ending IP.

In the "desktop.template" you see the #IP# portion. Every other field gets filled in correctly. The problem is I have to refernce a different variable $IPLIST.
Is there a way to create another for loop then will assign the right IP's to the right devices? i attempted to nest another for loop inside the original but that did not work.

Am I making this harder than it needs to be? Is there an easier way to go about this?
 
Old 11-19-2005, 03:31 PM   #2
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 33
If you embed the templates into your script as "hereis" documents you can use the variables instead of the #blah# placeholders. Then just echo the hereis document into the wanted file.
 
  


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
Bash Scripting Question fiod Linux - Newbie 4 11-19-2005 05:09 AM
bash scripting question bmfan Linux - Software 6 11-04-2005 08:54 PM
Bash scripting question. pete1234 Programming 23 09-22-2005 06:52 PM
Bash Scripting Question jsimmonds Programming 2 06-16-2005 09:07 AM
Bash scripting question Hammett Linux - General 4 11-29-2004 06:29 AM

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

All times are GMT -5. The time now is 05:59 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