×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

mkdir Problem

mkdir Problem

mkdir Problem

(OP)
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?

RE: mkdir Problem

what you have should work, but, you could try chmoding it after you create it, if it doesn't

adam@aauser.com

RE: mkdir Problem

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

RE: mkdir Problem

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

RE: mkdir Problem

(OP)
Huzzah! I tried this:

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

the open and close parans is what PERL didn't like.  

RE: mkdir Problem

(OP)
also checked this out I cannot use $MODE it only works if i have the actuall number in there 0777  

RE: mkdir Problem

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.
http://www.oac-design.com

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close