[LearnAdmin] Script to import csv into dhcpd.conf import multiple mac bindings

66 views
Skip to first unread message

Naresh Surampudi

unread,
Aug 6, 2013, 6:24:20 AM8/6/13
to learnadmin+g...@googlegroups.com
make sure your csv file is in this order MAC,IP,NAME and file name of csv is ips.csv
Once that is done just run the script and check mac_out.txt which is file to be imported in dhcpd.conf

!/bin/bash

INPUT=ips.csv
OUTPUT=mac_out.txt
OLDIFS=$IFS
IFS=","
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
[ -f $OUTPUT ] && { rm $OUTPUT; }
[ ! -f $OUTPUT ] && { touch $OUTPUT; }
while read mac ip uname
do
echo "host $uname {" >> $OUTPUT
echo -e "\thardware ethernet $mac;" >> $OUTPUT
echo -e "\tfixed-address $ip;" >> $OUTPUT
echo "}" >> $OUTPUT
done < $INPUT

IFS=$OLDIFS




--
Posted By Naresh Surampudi to LearnAdmin at 8/06/2013 03:54:00 PM
Reply all
Reply to author
Forward
0 new messages