Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mkdir Problem

Status
Not open for further replies.

jerehart

Programmer
Jun 10, 1999
61
US
Hey, I am having problems with perl's mkdir function, I can't seem to set any permissions. The script is running on Solaris 2.5.1.

$MODE = "0777";
$Dir = "/tools/build/Operate1.2";

mkdir ($Dir, $MODE) || die "Could not make directory $Dir: $!\n";

when I ls the directory it has the following permissions
dr--x--x

do I have to use umask? If I do, how do I?
 
what you have should work, but, you could try chmoding it after you create it, if it doesn't adam@aauser.com
 
A little playing around and this is what I think may be the case.....

This is one of the few places where I think Perl is actually counter-intuitive. The MODE that is specified with the mkdir function is modified by the current UMASK. UMASK actually turns OFF bits according to how it is set. So, when.....

#!/usr/local/bin/perl
mkdir tempDir,0777;

The permissions on that new dir may or may not be 777. The current umask will tweak the mkdir operation and may turn some bits off. I'm not clear how to set the umask, but this creates a dir that is wide open.

#!/usr/local/bin/perl
umask 0; # leave all bits alone.
mkdir tempDir,0777;

'hope this helps....


ponder....ponder....ponder.......
Results of playing with other umask settings....
umask 1; # drwxrwxrw-
umask 2; # drwxrwxr-x
umask 3; # drwxrwxr--

and so on..... although I don't yet see the pattern....
umask 16; # drwxr-xrwx ..... so how does 16 match up to that?????

Anyone out there have any education for me?




keep the rudder amid ship and beware the odd typo
 
you probably want to catch the umask setting before playing with it and put it back after you are finished.




keep the rudder amid ship and beware the odd typo
 
Huzzah! I tried this:

mkdir $Dir, $MODE || die "etc....";

the open and close parans is what PERL didn't like.
 
also checked this out I cannot use $MODE it only works if i have the actuall number in there 0777
 
The mode is octal. So you have to set your string to an octal before using it in a chmod application. The automatic string-to-number conversion you are used to assumes base 10.

$mode = "0777";
$mode = oct($mode);

or just set it to a number in the first place:

$mode = 0777;

"Permissions in the umask are turned off from 0666 (so, for example, the common umask default value of 022 results in new files being created with permissions 0666 & ~022 = 0755 = rw-r--r--)." (man umask)

"umask EXPR

Sets the umask for the process to EXPR and returns the previous value. If EXPR is omitted, merely returns the current umask.
" (perldoc umask)
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top