Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: chmod in perl script

by bellaire (Hermit)
on Feb 04, 2011 at 14:37 UTC ( #886218=note: print w/replies, xml ) Need Help??


in reply to chmod in perl script

You do use chmod, but you have to keep in mind that unlike the command-line chmod, which can simply flip bits on or off, perl's chmod sets the entire permission set as a single unit. Basically, you have to read the current permissions off the file using stat, add group sticky to those permissions bitwise, and then apply the new permissions using chmod. I think the group sticky bit is 02000, so that'd be:
my $filename = 'filename'; my $perms = ((stat($filename))[2] & 07777); # Just permissions, not + type my $newperms = $perms ^ 02000; # Add the group sticky +bit chmod $newperms, $filename or die "Could not change permissions: $!";

Replies are listed 'Best First'.
Re^2: chmod in perl script
by mcleary (Initiate) on Feb 08, 2011 at 19:09 UTC

    Thanks a lot Monks!

    I wound up using bellaire's suggestion and it worked perfectly.

    Take care, Michele

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://886218]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2019-10-17 02:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?