[EMAIL PROTECTED] wrote: > > Folks, Hello,
> I used my linux box running perl 5.8 to develop a small script that > scans a list of directories and searches for files that dont have the group > set to "productn" or "dialup". It works great on my linux box, but now > I need to run it on our sun systems which are running perl version 5.005_02. > (Ungrading perl is not a solution unfortunatly, developers would freak out). > It doesnt seem to work at all on the sun systems. It never seems to > enter the directories and doesnt find anything. Does the UID that the program runs under have permission to traverse those directories? > A normal program run looks like this on my linux box... > > [EMAIL PROTECTED] mcunning]$ ./scan-novell > Checking the directory: /nfs/links/live.run > Filename - GroupID (thats not productn or dialup) > ------------------------------------------------- > /nfs/links/live.run - root > /nfs/links/live.run/passwd - root > /nfs/links/live.run/test4 - nut > Checking the directory: /nfs/links/prefixes > Filename - GroupID (thats not productn or dialup) > ------------------------------------------------- > /nfs/links/prefixes - root > /nfs/links/prefixes/passwd - root > /nfs/links/prefixes/test3 - root > /nfs/links/prefixes/test4 - root > /nfs/links/prefixes/testsubdir - root > /nfs/links/prefixes/testsubdir/test6 - nut > Checking the directory: /nfs/links/transmit > Filename - GroupID (thats not productn or dialup) > ------------------------------------------------- > /nfs/links/transmit - mcunning > > A bad run on one of my sun systems looks like this.. > > mickey(mcunning)$ ./scan-novell > Checking the directory: /nfs/links/live.run > Filename - GroupID (thats not productn or dialup) > ------------------------------------------------- > Checking the directory: /nfs/links/params > Filename - GroupID (thats not productn or dialup) > ------------------------------------------------- > Checking the directory: /nfs/links/prefixes > Filename - GroupID (thats not productn or dialup) > ------------------------------------------------- > Checking the directory: /nfs/links/storage > Filename - GroupID (thats not productn or dialup) > ------------------------------------------------- > Checking the directory: /nfs/links/transmit > Filename - GroupID (thats not productn or dialup) > ------------------------------------------------- > Can't call method "name" on an undefined value at ./scan-novell line 41. Your call to getgrgid($gid)->name is complaining because the value in $gid cannot be found in /etc/group. > Any ideas where I am going wrong? There could be a problem with NFS mounted files? > The code is below.. > Thanks for any help you can offer. Mike > -------------------------------------------------------------------------------------- > > #!/usr/bin/perl #!/usr/bin/perl -w use strict; You should enable warnings and strict while developing your program. > # This program will scan the novell nfs mounts on a > # host, if each one exists, for permission problems. > # It will then list out the files that need to be > # fixed. > # > # MC - 9/10/03 > > use File::Find; > use File::stat; > use User::grent; You don't really need File::stat and User::grent as these functions are built in to perl. > $basedir = "/nfs/links/"; > @dirlist = qw(live.run params prefixes storage transmit); > *name = *File::Find::name; You are not using $name anywhere so why is this here? > foreach $directory (@dirlist) { > if ( -d "$basedir$directory"){ > print "\n"; > print "Checking the directory: $basedir$directory\n"; > print "Filename - GroupID (thats not productn or dialup)\n"; > print "-------------------------------------------------\n"; > find(\&wanted, "$basedir$directory"); > } > } > > sub wanted { > my $check = stat($_); > return unless $check; > > if ( -d $_ || -f $_ ) { You just stat()ed $_ and now you are stat()ing $_ two more times. > my $groupname = group($check->gid()); > if ($groupname ne "productn" && $groupname ne "dialup"){ > print "$File::Find::name - $groupname\n"; > } > } > } > > sub group { > my $gid = shift; > $group{$gid} = getgrgid($gid)->name || "#$gid" > unless defined $group{$gid}; You should use exists instead of defined. > return $group{$gid}; > } Try this and see if it works any better: #!/usr/bin/perl -w use strict; # This program will scan the novell nfs mounts on a # host, if each one exists, for permission problems. # It will then list out the files that need to be # fixed. # # MC - 9/10/03 use File::Find; # If you require root access uncomment the next line #$< and die "Must be root to run this program.\n"; my $basedir = '/nfs/links'; my @dirlist = map "$basedir/$_", qw( live.run params prefixes storage transmit ); foreach my $directory ( @dirlist ) { next unless -d $directory; print "\n"; print "Checking the directory: $basedir$directory\n"; print "Filename - GroupID (thats not productn or dialup)\n"; print "-------------------------------------------------\n"; find( \&wanted, $directory ); } sub wanted { my $gid = (stat)[5] or return; return unless -d _ or -f _; my $groupname = getgrgid $gid || "#$gid"; if ( $groupname ne 'productn' && $groupname ne 'dialup' ){ print "$File::Find::name - $groupname\n"; } } __END__ John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]