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?