I am writing a Perl script to automatically generate a netlogon.bat file for Samba whenever a user logs onto a domain. The only parameter that is passes to it is the username. My problem is that different groups get some of the same mappings. What I really need to do is filter out duplicate lines in the finished output. I tried piping the output through 'uniq' but it only filters successive duplicate lines. Anyone have any suggestions?

#!/usr/bin/perl

my $user = shift;
my $drives = {F => "NET USE F: \\\\SKYLINE\\SKYLINEF\r\n",
H => "NET USE H: \\\\SKYLINE\\SHARE\r\n",
I => "NET USE I: \\\\SHIPPING1\\INVENTORY\r\n",
M => "NET USE M: \\\\SKYLINE\\SKYLINEM\r\n",
S => "NET USE S: \\\\SHIPPING1\\SHOP\r\n",
Y => "NET USE Y: \\\\ACCOUNTING\\FLTSCHOOL\r\n",
Z => "NET USE Z: \\\\ACCOUNTING\\MAINT\r\n"};
my $which = {accounting => "F H I M S Y Z", mech => "I M S Z", dispatch => "M", instructors => "M"};
my $groups = `cat /etc/group | grep ${user} | cut -d ':' -f 1`;
$groups =~ s/\n/\:/sg;


# Start generating logon script
#open LOGON, ">/usr/local/samba/netlogon/${user}.bat";
open LOGON, ">/tmp/${user}.bat";
print LOGON "[EMAIL PROTECTED] OFF\r\n";

foreach $group (split /:/, $groups) {
  foreach $drive (split / /, $which->{$group}) {
    print LOGON $drives->{$drive};
  }
}

close LOGON;

--
Andrew Gaffney


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to