Shell/Perl Script to edit dhcpd.conf


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell/Perl Script to edit dhcpd.conf
# 1  
Old 11-20-2006
Shell/Perl Script to edit dhcpd.conf

Hi,
I need to get a script together to edit the dhcp service configuration file dhcpd.conf.

Mac addresses are defined in classes ex.
class "HOST1" { match if substring (hardware, 1,18)=00:11:11:FF:FF:FF;}
class "HOST2" ...
class "HOST3" ...
...

followed by allow or deny statements:
deny members of "HOST1";
allow members of "HOST2";
...
...

The script should search for the MAC address entered by the user and if found should deny that class by changing allow to deny in the statement for that class and/or deleting the class.
If not found it should create a class with the given MAC address and add a deny statement for that class in the above given format.

I would appreciate any ideas or help...

Thanks

SB
# 2  
Old 11-21-2006
one approach:
1. read entire file dhcp.conf in an array
2. then do the operations in that array (adding, editing, removing lines) and then
3.write the contents of array back to the file
# 3  
Old 11-21-2006
This, of course, is just the logic, the implementation could be "done in more than one way" Smilie
# 4  
Old 11-21-2006
Any detailed ideas about the implementation?
# 5  
Old 11-22-2006
1. to read the file in an array:
Code:
my $dhcp_filename = "/path/to/dhcp.conf";
open (DHCP_FILE, "< $dhcp_filename")  or  die "Can not read file $dhcp_filename : $!";
my @dhcp_file = <DHCP_FILE>;
close (DHCP_FILE);

2. use the functions pop, push, shift, splice, and unshift to do operations on the array

3. to write contents of array back to the file:
Code:
open (DHCP_FILE, "> $dhcp_filename")  or  die "Can not write to file $dhcp_filename : $!";
print DHCP_FILE @dhcp_file;
close (DHCP_FILE);

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Changes in dhcpd.conf do not make a difference in DHCP service behaviour

Hi Experts, Our DHCP server currently answers the DHCP Discover requests from ServerX. In our dhcpd.conf file there are parameters defined for ServerX. Now we introduced some additional Servers into the network and want them to get service from the same DHCP server. Similar configuration... (13 Replies)
Discussion started by: ekorgur
13 Replies

2. Shell Programming and Scripting

Listing IPs from the dhcpd.conf

Hy everybody, Within a dhcpd.conf file, we got some fixed IP adresses from 192.168.0.1 - 192.168.0.254. Sample: #ddns-update-style interim; ddns-update-style none; ignore client-updates; deny client-updates; authoritative; #### By red for PXE Booting allow booting; allow bootp; ###... (17 Replies)
Discussion started by: hermouche
17 Replies

3. Shell Programming and Scripting

Shell Script to check dhcp conf file

Hi, I have to prepare a script to check the dhcp conf file. The script has to check for a specific parameter called circuit ID. If the Circuit ID is unique it should show the output that it is unique and if it is duplicate it should show that the Circuit ID is duplicate. I have prepared the... (4 Replies)
Discussion started by: Crazy_Nix
4 Replies

4. Shell Programming and Scripting

Help with Perl to change dhcpd.conf file

Hi all, I am too new for this stuff and i am lost in perl tutorials. I need help to change dhcp entries in .conf file with a perl script. The file entries are like below : host bertha-clp-0 { hardware ethernet AA:0A:A0:00:6c:40; fixed-address 10.10.10.72; option... (6 Replies)
Discussion started by: ekckabatop
6 Replies

5. UNIX for Dummies Questions & Answers

edit /etc/syslog.conf (Solaris 10)

Hi, Im editing the file /etc/syslog.conf for Solaris 10 server in production. I need to add "auth and authpriv.": someone set the same? Have been successful? I would appreciate any suggestions. Greetings. The unmodified arhive is: (0 Replies)
Discussion started by: musul
0 Replies

6. Shell Programming and Scripting

shell script to edit a file

i have a file called number which contains data as 1 2 3 4 5 6 7 8 9 0 9 8 7 6 5 4 3 2 1 0 0 1 2 3 4 needed a shell script to print the output as 1 7 7 1 4 and (2 Replies)
Discussion started by: jacky29
2 Replies

7. Shell Programming and Scripting

help on a perl script to edit file

Hi, sample file looks like this.. <hp> <name> <detail>adsg</detail> ... ... </name><ft>4264</ft> </hp> I need to edit the last but one line using perl script. I want the format to be .. <hp> <name> <detail>adsg</detail> ... ... </name> (9 Replies)
Discussion started by: meghana
9 Replies

8. Linux

dhcpd.conf - static route

Hi, I've setup DHCP Server on RH linux AS3 and everything works fine except static routes. They are not getting effected on client systems. My dhcpd.conf: +++++++++++ ddns-update-style interim; ddns-updates off; option domain-name-servers 192.168.116.122; option domain-name... (3 Replies)
Discussion started by: prvnrk
3 Replies

9. UNIX for Dummies Questions & Answers

Cannot edit inetd.conf???

I'm trying to edit the inetd.conf but for some reason when I vi into it, it says "Read Only" even though I am root and the perms are 777?!? (2 Replies)
Discussion started by: shorty
2 Replies

10. Linux

dhcpd.conf

I have intall a REdhat 9.0 as a server and Ive configure to act as a DHCP however Im having technical problems b/c the file /etc/dhcpd.conf does not exists. I went to the text edit and I created : subnet 192.192.168.100.0 netmask 255.255.255.0 { range 192.168.100.10 192.168.100.150;... (1 Reply)
Discussion started by: keliy1
1 Replies
Login or Register to Ask a Question