Cosasdelinux’s Weblog

julio 1, 2011

Create dhcpd conf from csv file with mac and hostname

We have a file calle ips and the file contens

00:1c:c4:64:a0:c0;hostname1;
1c:c1:de:0f:f2:c2;hostname2;

create a createdhcpd.pl with this
#!/usr/bin/perl

open (FILE, ‘ips’);
open (MYFILE, ‘>data.txt’);
while () {
chomp;
($mac, $host) = split(“;”);
print MYFILE “host $host { \n hardware ethernet $mac\; \n fixed-address $host\; \n \} \n \n”;
print “\n”;
}
close (FILE);
close (MYFILE);
exit;

Run it, and then check data.txt .

Example data.txt
host hostname1 {
hardware ethernet 00:1c:c4:64:a0:c0;
fixed-address hostname1;
}

host hostname2 {
hardware ethernet 1c:c1:de:0f:f2:c2;
fixed-address hostname2;
}

Advertisement

Dejar un comentario »

Aún no hay comentarios.

RSS feed para los comentarios de esta entrada. URI para TrackBack.

Deja un comentario

Fill in your details below or click an icon to log in:

Logo de WordPress.com

You are commenting using your WordPress.com account. Log Out / Cambiar )

Twitter picture

You are commenting using your Twitter account. Log Out / Cambiar )

Facebook photo

You are commenting using your Facebook account. Log Out / Cambiar )

Connecting to %s

Theme: Rubric. Blog de WordPress.com.

Seguir

Get every new post delivered to your Inbox.