Dhcp.config file scripting assistance

Hello everyone! I am brand new at this forum thing and wanted to thank all of you for your time and help in advance for helping me troubleshoot my issue.

I am fairly new to shell scripting and scoured the entire internet to find a solution for my issue to no avail and hope you're able to help.

I'm trying to create a dhcp.config file as listed below:

===================================

#!/bin/bash

count=88
ipadd=101


           until [ $ipadd -gt 110 ]
           do
                    echo "               host     somehost$count    {
                    option host-name   somehost$count;
                    hardware ethernet ff:ff:ff:ff:ff:ff; <---Where I need help
                    fixed-address 192.168.100.$ipadd;
                   {" > output.txt
                              count=`expr $count + 1`
                              ipadd=`expr $ipadd + 1`
          done

=======================================

The script works well by incrementing the number for the hostname by the variable $count AND incrementing the fixed-address by 1 with $ipadd. However, my dilemma is trying to get the hardware MAC address to change with being fed from another file called MAC.txt.

The MAC.txt file contains MAC addresses for the clients. Example looks like this:

=======================================

11:22:33:44:55:66
aa:bb:cc:dd:ee:ff
xx:xx:xx:xx:xx:xx
33:33:33:33:33:33
55:55:55:55:55:55

=======================================
And so on...

I looked everywhere to find out how I can take the text from this file and put it in place of where my MAC address is inside of the "dhcp.config" script I created.

So basically I would like this to happen:

========================================

host     somehost1    {
                    option host-name   somehost1;
                    hardware ethernet 11:22:33:44:55:66
                    fixed-address 192.168.100.4;
                   {"

host     somehost2    {
                    option host-name   somehost2;
                    hardware ethernet aa:bb:cc:dd:ee:ff
                    fixed-address 192.168.100.5;
                   {"

host     somehost3    {
                    option host-name   somehost3;
                    hardware ethernet xx:xx:xx:xx:xx:xx
                    fixed-address 192.168.100.6;
                   {"

=========================================
And so on... MAC addresses all incrementing with the hostname and fixed-address in succession.

Clear as mud? :slight_smile: I've been exploring with sed and awk, believing there is a way to do it. To be honest, I am not at that experience level and lack the knowledge and experience to perform those operations as of yet. But learning more and more every day! How could I not since sed is awesome and my name just happens to be Sed. :slight_smile:

I am at a wall right now and am stuck...it's not a very good feeling :stuck_out_tongue: I know this can be done and I've worked so hard to find a solution, but am limited by knowledge.

If anyone is able to help me out with this, I would be so appreciative and thankful. I already am by you taking a look at this to begin with. I really hope someone can help and I will check back here for a solution if anyone was able to create one. Thank you all very much in the meantime!

-Sedrocks

Try this:-

MAX_IPADD=101
MAX_COUNT=88

IPADD=1
COUNT=1

while read mac_addr
do

if [ ${IPADD} -gt ${MAX_IPADD} ]
then
        break;
else
{
echo "host somehost${COUNT} {
option host-name somehost${COUNT};
hardware ethernet ${mac_addr}
fixed-address 192.168.100.${IPADD};
{"
} >> output.txt

IPADD=`expr ${IPADD} + 1`
COUNT=`expr ${COUNT} + 1`
fi

done < MAC.txt

I hope this helps.

1 Like

bipinajith...Thank you! I am going to try this and let you know how it turns out. Thank you very much for your reply and solution!

-Sedrocks

---------- Post updated 11-09-12 at 08:05 AM ---------- Previous update was 11-08-12 at 04:16 PM ----------

bipinajith! The script works PERFECTLY! THANK YOU so much again! I very much appreciate all of your help. Have a great day!