Find the answer to your Linux question:
Results 1 to 4 of 4
I just upgraded servers, and I'm now on 'perl, v5.8.8 built for i386-linux-thread-multi' and a simple log script doesn't work. I got it changed to... Code: #!/usr/bin/perl use strict; use ...
  1. #1
    Just Joined!
    Join Date
    May 2010
    Posts
    3

    Simple perl log code not working.

    I just upgraded servers, and I'm now on 'perl, v5.8.8 built for i386-linux-thread-multi' and a simple log script doesn't work. I got it changed to...

    Code:
    #!/usr/bin/perl
    
    use strict;
    use warnings;
    use POSIX qw(strftime);
    use CGI;
    use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
    
    my $cgi             = CGI->new;
    my $database        = "/full_path/file.shtml";
    my $shortdate       = strftime("%m/%d/%y %H:%M:%S %Z", localtime);
    my $remote_addr     = $ENV{'REMOTE_ADDR'} || 'N/A';
    my $script_uri      = $ENV{'SCRIPT_URI'} || 'N/A';
    my $http_user_agent = $ENV{'HTTP_USER_AGENT'} || 'N/A';
    my $http_referer    = $ENV{'HTTP_REFERER'} || 'N/A';
    
    print $cgi->header, $cgi->start_html;
    warningsToBrowser(1);
    print $cgi->p("$remote_addr - $shortdate - $script_uri - $http_user_agent<!-- - $http_referer-->");
    
    open my $dbhandle, '>>', $database
       or die "failed to open '$database' for appending: $!";
    
    print $dbhandle "$remote_addr - $shortdate - $script_uri - $http_user_agent<!-- - $http_referer--><BR>\n";
    close $dbhandle;
    where it only recognizes the time. It doesn't recognize any of the $ENV stuff. It spits out

    N/A - 05/25/10 10:53:14 PDT - N/A - N/A - N/A

    in to the log file. It only does this logging when accessed via SSH, and does nothing when called from the script. (Script spits out the ISE message.)

    The original script that worked fine before the server upgrade...

    Code:
    #!/usr/bin/perl
    use CGI ':standard';
    use warnings;
    
    $database = "/full_path/file.shtml";
    
    $shortdate = `date +"%D %T %Z"`; 
    chop ($shortdate);
        open (DATABASE,">>$database");
            print DATABASE "$ENV{'REMOTE_ADDR'} - $shortdate - $ENV{'SCRIPT_URI'} - $ENV{'HTTP_USER_AGENT'}<!-- - $ENV{'HTTP_REFERER'}--><BR>\n";
        close(DATABASE);
    
    {
       print "Content-Type: text/html\n\n";
    print <<EOM;
    <PRE>
    </PRE>
    EOM
       exit;
    }
    Does any one know how to get one of those versions working?

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    The problem seems pretty obvious: your environment isn't set up properly. Modify the user's .bashrc file to set up the environment, and then the variables will be read correctly.
    DISTRO=Arch
    Registered Linux User #388732

  3. #3
    Just Joined!
    Join Date
    May 2010
    Posts
    3

    Question

    Turns out it's permission issues.

    I started getting a *useful* 'ISE' message...

    97.125.24.27 - 05/25/10 11:18:46 PDT - N/A - Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.3) Gecko/20100401 Ant.com Toolbar 2.0.1 Firefox/3.6.3

    Software error:

    failed to open '/var/www/vhosts/ANOTHERDOMAIN.com/httpdocs/directory/file.shtml' for appending: Permission denied at thisfile.cgi line 21.

    which is

    open my $dbhandle, '>>', $database
    or die "failed to open '$database' for appending: $!";

    so I then moved the log file to the same domain, chmod it 777, changed the path in the script...and the original version of the script worked just fine.

    Is there any way to make the script be allowed to post data to a file in another domain on the same server? The file on the other domain and the directory that it's in is both chmod 777.

  4. #4
    Just Joined!
    Join Date
    May 2010
    Posts
    3
    chmod'ing all folders back to the domain 777 does it. For example, two folders and a file...

    httpdocs/folder/file.shtml

    and it then works.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...