Dhcp.config file scripting assistance


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Dhcp.config file scripting assistance
# 1  
Old 11-08-2012
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:

===================================
Code:
#!/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:

=======================================
Code:
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:

========================================
Code:
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? :-) 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. Smilie

I am at a wall right now and am stuck...it's not a very good feeling :P 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

Last edited by sedrocks; 11-08-2012 at 04:54 PM..
# 2  
Old 11-08-2012
Try this:-
Code:
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.
This User Gave Thanks to Yoda For This Post:
# 3  
Old 11-09-2012
Dhcp.config file scripting assistance

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!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Noob to scripting needs some assistance

Hello, I am in a Unix class and have been out of town. I have been tasked to generate a couple of scripts and ahve never done it before. I have a virtual machine running Ubuntu. The task is below Prompt the system administrator for all valid input parameters Generate a menu to ask which... (1 Reply)
Discussion started by: jkeeton81
1 Replies

2. Shell Programming and Scripting

sed newbie scripting assistance

Howdy folks, I'm trying to craft a log file summarisation tool for an application that creates a lot of duplicate entries with only a different suffix to indicate point of execution. I thought I'd gotten close but I'm clearly missing something. Here's a genericized version: A text_file... (3 Replies)
Discussion started by: mthespian
3 Replies

3. Shell Programming and Scripting

Using ii for irc chat - scripting assistance?

I am using ii for irc on my pogoplug... hxxp://hg.suckless.org/ii/file/d163c8917af7/FAQ If you look at the bottom of there, it states 31 What other fancy stuff can I do with ii? 32 ---------------------------------------- 33 It is very easy to write irc bots in ii: 34... (3 Replies)
Discussion started by: spartan2006
3 Replies

4. Solaris

DHCP config struggles (serious struggle, or maybe just being stupid ...)

I have a straaaaaaange problem with a Solaris 10 host acting as a dhcp server. I can not get an ip adress allocated even though the configuration works in an almost exact setup for another Solaris 10 host. The <host> in question has one piece of BOOTP booting <equipment> hooked up to bge0, with... (0 Replies)
Discussion started by: larske
0 Replies

5. Shell Programming and Scripting

Shell script that will compare two config files and produce 2 outputs 1)actual config file 2)report

Hi I am new to shell scripting. There is a requirement to write a shell script to meet follwing needs.Prompt reply shall be highly appreciated. script that will compare two config files and produce 2 outputs - actual config file and a report indicating changes made. OS :Susi linux ver 10.3. ... (4 Replies)
Discussion started by: muraliinfy04
4 Replies

6. IP Networking

DHCP config issue?

I searched the forum and found a similar question (https://www.unix.com/ip-networking/119108-dhcpd-related-questions.html), but my config is already utilizing the suggested fix... :( My setup: eth0 connected to Motorola DSL Modem via bridged mode (giving the public IP to the interface), IP... (1 Reply)
Discussion started by: macwunder
1 Replies

7. Shell Programming and Scripting

Assistance in Perl scripting

PFA file "color.txt". Note : There is no newline character in the file. I have manually inserted the newline char to make it easy to understand. I am expecting out in the form as specified in second file "out.txt" I need a perl script to perform the task. Thanks in advance. (2 Replies)
Discussion started by: deo_kaustubh
2 Replies

8. Shell Programming and Scripting

Scripting neophyte needs file manipulation assistance

I need to write two shell scripts for an rsync backup solution. The first script will copy all backed up files into a folder named after the original folder, plus a date stamp (so e.g. if the original folder name is 'foo' and is backed up on the 10th of September, then the backup folder will be... (0 Replies)
Discussion started by: LambdaCalculus
0 Replies

9. Shell Programming and Scripting

Assistance with regex and config files

I am trying to write a shell script that will such in data from a config file. The script should mount device nodes that are contained in a config file in the following format: # filesystem type # read/write #device # Mount Point xfs w ... (1 Reply)
Discussion started by: pryker
1 Replies

10. Solaris

DHCP DNS Config

I'm running Solaris 9 and I need my box to request it's DNS servers off a DHCP server - can I do this? (1 Reply)
Discussion started by: Jdogg
1 Replies
Login or Register to Ask a Question