Script to import csv into dhcpd.conf import multiple mac bindings

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


1 comment:

Unknown said...

Thanks very much for this script!