3 Files are needed:
A Template Configuration
A Source
And the script itself
::: TEMPLATE FILE :::
# This is a standard config file
service password-encryption
username admin privilege 15 password cisco
aaa new-model
aaa authentication login default local
aaa authorization exec default local
hostname VAR_HOSTNAME
interface Vlan1
ip address VAR_IPADDR 255.255.255.0
ip default-gateway VAR_DG
line vty 0 4
login
interface gi0/1
description !! Metro-Ethernet !!!
switchport mode access
no shutdown
:: SOURCE FILE ::
miami,10.20.8.253,10.20.8.254
ftl,10.20.9.253,10.20.8.254
boca-raton,10.20.10.20,10.230.8.254
tampa,10.20.11.253,10.20.8.254
atl,10.20.12.253,10.20.8.254
:: SCRIPT ::
#!/bin/bash
IMPORT="/home/cisco/data/import-data.txt"
TEMPLATE="/home/cisco/data/import-template.txt"
for i in `cat ${IMPORT}`
do
VAR_HOSTNAME=`echo $i | awk -F, '{print $1}'`
VAR_IPADDR=`echo $i | awk -F, '{print $2}'`
VAR_DG=`echo $i | awk -F, '{print $3}'`
cat $TEMPLATE | sed -e s/VAR_HOSTNAME/$VAR_HOSTNAME/g \
-e s/VAR_IPADDR/$VAR_IPADDR/g \
-e s/VAR_DG/$VAR_DG/g \
| tee /home/cisco/output/$VAR_HOSTNAME.txt 1>/dev/null
done
:: HOW IT WORKS ::
Source file is CSV format. Add the correct field based on your requirements, change the variables on the template file to match the CSV file. Then run the command 'sh %script-name%'
You can obviously use this as a stepping off point and add or remove as needed.
Good luck