Hi all,

I have been trying to get the mode of a directory with the stat function in 
perl (currently using the one from File::stat) with no success so far. 
Basically I want to check if a given directory is having 1777 permission (like 
/tmp) and I was thinking about storing the mode of the directory in a variable 
and check that variable for the value 1777.

With this setup, however I'm unable to get the actual octal mode of the 
directory stored into the variable. I'm getting a weird value and I can print 
the actual value by masking off the type using printf "%40o", but here I don't 
have to print the perm, want to get it to use it in an if condition. 
 
#!/usr/bin/perl
use File::stat;
 my $dir=$ARGV[0];
 $st = stat($dir) or die "No $dir: $!";
 my $stat_mode = $st->mode;
 my $mode = $stat_mode & 07777;
print "stat_mode: $stat_mode\tmode: $mode\n";
printf "Actual value:%04o\n",$mode;
 
But, as you know, $mode is not storing the actual mode value. If the actual 
mode of the directory is 0755, the following is the output:
stat_mode: 16877        mode: 493
Actual value:0755

Could anyone tell me how can I check if the given directory is having 1777 perm 
mode?

Regards,
Akhthar Parvez K
http://Tips.SysAdminGUIDE.COM
UNIX is basically a simple operating system, but you have to be a genius to 
understand the simplicity - Dennie Richie

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to