I need to write a code so that it could verify the DIRECTORY permission. Been 'google' around and looks to me that the use File::stat may match my needs. However, when I tried on my code as below, it doesn't give result as I aspected. I'm looking for if the directory is not having the read and execute permission , it will show the directory name. Can anybody help? Below are lines of code I found from web, tried but seem not giving a favor output.
#! /usr/bin/perl
use strict ;
use warnings ;
use File::stat ;
my $path = "/nfs/ch/test_dir" ;
opendir (DH, $path) || die "Fail to open dir:$!\n" ; ;
my @dir = readdir (DH) ;
closedir (DH) ;
foreach my $dir (@dir) {
print "DIR: $dir\n" ;
$dirmode = (stat($dir)) [2] ;
printf "Permissions are %04o\n", $dirmode & 07777;
print "DIRmode= $dirmode\n" ;
}
The output is like this:- DIR: groupA Permissions are 0000 DIRmode= DIR: groupB Permissions are 0000 DIRmode=
I'm actually looking for code which could output the directory name when it found the directory at the search path is not having the GROUP and WORLD PERMISSION for read and execute. Thanks in advanced.