Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Newbie Question: Permission Denied

by tommcq (Initiate)
on Jul 18, 2008 at 04:33 UTC ( #698504=perlquestion: print w/replies, xml ) Need Help??

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

Ok, I've got a simple little script that I wrote which takes some text, strips out superfluous characters then appends the cleaned up text to file. Like I said, simple. I've been using it without problem for months, up until yesterday that is, when I made the mistake of running it as root. Since then, if I try to run it as under my normal user account, it reaches

open my $filehandle, ">> $fname" or die $!; print $filehandle $data; close $filehandle;
and quits with 'Permission denied' and diagnostics reporting 'The setuid emulator in suidperl decided you were up to no good'.

I've done all the obvious stuff with ownership and permissions. Even tried shredding the output file and replacing it with a brand new one but the problem remains. Can somebody give a me a clue? I really don't want to have to fire up the root account every time I run this thing.

For info, I'm using Fedora fc8 with perl 5.8.8 (ie. the one that comes bundled with Fedora).

Thanks in advance,

Replies are listed 'Best First'.
Re: Newbie Question: Permission Denied
by pc88mxer (Vicar) on Jul 18, 2008 at 06:26 UTC
    The error is just Permission denied, and you are getting it because you can't write to $fname or $fname doesn't exist and you can't create it.

    Just debug the problem a little further by inserting these statements before the call to open():

    die "file '$fname' does not exist" unless (-e $fname); die "file '$fname' is not a regular file" unless (-f $fname); die "file '$fname' is not writable" unless (-w $fname);
    That should tell you what's wrong.
Re: Newbie Question: Permission Denied
by djp (Hermit) on Jul 18, 2008 at 06:35 UTC
    It's likely you don't have write permission on the output directory, possibly the permissions changed when you ran as root. If that's the problem, sudo to root and change the permissions back.
Re: Newbie Question: Permission Denied
by tommcq (Initiate) on Jul 18, 2008 at 09:38 UTC

    Thanks for taking the time to reply guys, some useful tips there that will be plenty useful in future.

    As to the solution for my problem, pc88mxer, your little debugging routine picked it up instantly. It turns out that running as root had changed the ownership and group of the output files to root and although I'd chown'd and chgrp'd the main output file back to my normal account, thanks to my own stupidity, I'd completely forgotten about a little logfile that the script also writes to. It's now fixed and everything is working fine.

    Once again, thanks to all,

      or die "Can't open $fname for writing : $!"
Re: Newbie Question: Permission Denied
by Anonymous Monk on Jul 18, 2008 at 06:25 UTC
    I've done all the obvious stuff with ownership and permissions.
    Such as? Please show us.

    Use of suidperl is highly discouraged.

      Actually, it's not clear the OP is using suidperl. You'll get that message from use diagnostics even from regular perl whenever you have a Permission denied error.

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2023-12-06 16:56 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (31 votes). Check out past polls.