http://qs1969.pair.com?node_id=88571

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 23: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 Zaxo (Archbishop) on Jun 15, 2001 at 03: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

Re: Strange File Not Found Error
by Anonymous Monk on Jun 14, 2001 at 23: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
Re: Strange File Not Found Error
by mr.nick (Chaplain) on Jun 15, 2001 at 01: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";
A reply falls below the community's threshold of quality. You may see it by logging in.