Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

CHMOD Question

by Anonymous Monk
on Nov 24, 2001 at 19:46 UTC ( [id://127269]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, Newby question... My script has written a file, but I can't get the script to change it's permissions... I've tried chomd 0755, $filename; Any help gratefully received...

Replies are listed 'Best First'.
Re: CHMOD Question (TMTOWTDI: umask instead of chmod)
by ybiC (Prior) on Nov 24, 2001 at 21:36 UTC
    You might find it advantageous to define fileperms *before* file creation by using umask, instead of *after* with chmod.
    #!/usr/bin/perl -w use strict; # de(clare|fine) variables: my $filename = 'my.file'; # set mask for "readable only by user who runs this script": umask 077; # create a file with perms defined by above mask: open (FH, ">$filename") or die "Error opening $filename: $!"; print FH "foo\n"; close FH or die "Error closing $filename: $!";

    If you've not used umask before, this Unixy tutorial does a decent job explaining the numbers.
        cheers,
        Don
        striving toward Perl Adept
        (it's pronounced "why-bick")

    Update: corrected mispeling of timtowdi in title

Re: CHMOD Question
by ask (Pilgrim) on Nov 24, 2001 at 19:55 UTC
    (assuming you just misspelled chmod). Try adding error checking, like
    chmod 0755, $filename or warn "Could not chmod $filename: $!"

     - ask

    -- 
    ask bjoern hansen, http://ask.netcetera.dk/   !try; do();
    
      Hi, $! gives permission denied.
Re: CHMOD Question
by Malus (Acolyte) on Nov 25, 2001 at 01:18 UTC
    Are you the file's user owner?
    redirecting to a file that already exists preserves its owner
    compare the files user owner with your euid.
    warn "WARN: not my file: $file" unless $> eq (stat($file))[4];

    If that doesn't help. Make sure that your not writing to
    an unfriendly NFS or the like.
    (from a UNIX shell) type: df -F nfs $file

    Good luck,
    Malus

      The file was created by the script so the script should have rights to chmod it?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://127269]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-03-28 17:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found