Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
XP is just a number
 
PerlMonks  

Strange File Not Found Error

by FouRPlaY (Monk)
on Jun 14, 2001 at 18:54 UTC ( [id://88571]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

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

I have a file that looks like this:
992535783 6 6 7 19 992536692 9 6 9 24 992537600 8 8 7 23 992538508 7 10 6 23 992539415 5 15 8 28 992540322 8 14 8 30 992541229 7 15 10 32 992542137 7 13 10 30 992542984 6 16 8 30 992543891 8 12 6 26

Which is epoch time followed by user's logged into three different rooms, followed by the total. I use this code to read it in and display it in pretty html:
#!/usr/bin/perl -w use strict; use CGI qw/:standard/; use CGI::Carp qw(fatalsToBrowser); my @headings = ('Time','MC3004','MC3005','MC3027'); my @rows = th(\@headings); open LABS, "/software/polaris-mfcf/data/local/w.stat" or die "Unable t +o open file: $!\n"; for (<LABS>) { my ($time,$num4,$num5,$num7) = split; $time = localtime($time); my $check = substr(localtime(time),4,6); push @rows, td([$time,$num4,$num5,$num7]) if $time =~ /$check/ +; } close LABS; print header; print start_html('Polaris Usage'); print table({-border=>undef}, caption(strong('Polaris Terminal Usage')), Tr(\@rows) ); print end_html;


When I run it gives a file not found error from the die command. But, the file does exist. I've tried running it from a different user's web space with a copy of the file and it works fine. When I run it from the command line, it runs fine. When I run it from the command line and pipe the output to a file, that file contains all the right/vaild html and output.

Does anyone know why, when I try to access the file from it's own directory it would be unable to find a file that exists?



FouRPlaY
Learning Perl or Going To die() Trying

Replies are listed 'Best First'.
Re: Strange File Not Found Error
by Chmrr (Vicar) on Jun 14, 2001 at 19:04 UTC

    My guess, in a word, would be permissions. The webserver is probably running as the "nobody" user or equivalent, which has very few privileges. Make sure that the w.stat file is chmod'd so as to be world-readable. The easiest way to do this is:

    chmod +r w.stat

    Update: As xphase_work states, $! normally spits out the more useful "Permission Denied" message in such cases. And FourPlay assures me that the directories and file in question are readable. $Chmrr->bark("wrong tree"); Perhaps the distinguished AM is on the right track?

    Update 2: Looks like the most excellent tye found the problem. Give the man a ++!

     
    perl -e 'print "I love $^X$\"$]!$/"#$&V"+@( NO CARRIER'

      I thought that was the problem, but I checked on my Solaris 2.7 system, and $! for perl 5.6 gives a Permission Denied error if the permissions are wrong. Is that just my system?

      -xPhase

        Possibly so, or it's possible I just stuck my foot in my mouth. It's still the first thing I'd check.

         
        perl -e 'print "I love $^X$\"$]!$/"#$&V"+@( NO CARRIER'

      Excellent thought. I forgot to mention that I tried not only the file, but each directory leading up to it. There all world readable.



      FouRPlaY
      Learning Perl or Going To die() Trying
Re: Strange File Not Found Error
by Anonymous Monk on Jun 14, 2001 at 19:15 UTC
    Do a print `pwd` in your script. Instant Enlightenment Guarateed!!
      Oops! Sorry I meant print `ls -l /`. (Hint: Many webserver are in chroot-Environment)
        I'm not sure where you're going with this...

        The ls -l / prints out the / directory as expected. What's the enlightenment?



        FouRPlaY
        Learning Perl or Going To die() Trying
fourplay, if you want help...
by princepawn (Parson) on Jun 14, 2001 at 20:21 UTC
    I would never waste my precious fingers trying to msg someone whose name is as hard to type as yours. Get an easy-to-type name and increase your chances of response from those who value their time.

    Second, what the people are saying above is that your CGI script is executed by webserver as a particular user (probably username nobody) who has certain permissions which are probably more limited than yours and that user can't open the file even though you can.

      You're an idiot.



      FouRPlaY
      Learning Perl or Going To die() Trying
      user names aren't case sensitive, PrInCePaWn :)

      What are you going to do about, say, £oki?

Re: Strange File Not Found Error
by mr.nick (Chaplain) on Jun 14, 2001 at 21:18 UTC
    I'd just like to add that the fragment
    open LABS, "/software/polaris-mfcf/data/local/w.stat" or die "Unable to open file: $!\n";
    doesn't do what you expect it to, IIRC. In reality, it's saying something like:
    open LABS, ("/software/polaris-mfcf/data/local/w.stat" or die "Unable to open file: $!\n")
    The or operator bonds to the string "/software/...", not to the open command. You'll want to do this instead
    open (LABS, "/software/polaris-mfcf/data/local/w.stat") or die "Unable to open file: $!\n";

    Update: Well! I'll be hogtied: "or" != "||". I had always assume that "or" and "and" were just common language equals to their || && counterparts. I didn't know their behaviors where different.

    mr.nick ...

      The or operator bonds to the string "/software/...", not to the open command

      That's the || operator, not the or operator:
      open FILE, "doesnotexist" or print "or\n"; open FILE, "doesnotexist" || print "|| #1\n"; open(FILE, "doesnotexist") || print "|| #2\n";
Re: Strange File Not Found Error
by Zaxo (Archbishop) on Jun 14, 2001 at 23:41 UTC

    Is any element of the path a symlink? Apache, for one, can be configured to refuse to follow symlinks for cgi.

    If that's the case, you can use a hard path, or else you may be able to set 'Options FollowSymLinks' in .htaccess.

    After Compline,
    Zaxo

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://88571]
Approved by root
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.