#!/usr/bin/perl # Joe G - 9/18/2012 # Turn on strict interpretation and error handling use strict; use warnings; # File operators use File::Glob; use File::Basename; # Open target udev file, emptying it open (my $udevFile, '>/etc/udev/rules.d/70-persistent-net.rules') or die "Couldn\'t open file to write: $!\n"; # Go through files matching pattern for (glob ('/sys/class/net/eth*/address')) { # Get name of device from path my $device = basename(dirname($_)); # Open it to get its contents open (H, '<'.$_); # Get contents my $mac = ; # Trim the newline off and close it chomp $mac; close H; # Debug print "Found $device with MAC $mac\n"; # Write it to the udev file. print $udevFile 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="'.$mac.'", ATTR{type}=="1", KERNEL=="eth*", NAME="'.$device."\"\n"; } # Close udevfile close $udevFile;