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

Good day Monks! I have been searching the web and trying different variations of code so that the end user via a web interface can see all of the server backup logs and select anyone of them to read the log. I am working on a test system which is RHEL 6. There is the dir "/var/log/vista/stcr2tsvr/" where the backup logs are stored and it has files in it. I have even chmod 777 all of the dirs. and files (Just for testing)When I call the script from IE I get the standard server error and when I tail /var/log/httpd/error_log I am presented with the following:

Tue Feb 24 14:11:10 2015] [error] [client 10.*.*.*] (2)No such file or + directory: exec of '/var/www/cgi-bin/rdp_backuplogs_test' failed [Tue Feb 24 14:11:10 2015] [error] [client 10.*.*.*] Premature end of +script headers: rdp_backuplogs_test
I am unsure where I am going wrong with the code:

#!usr/bin/perl use strict; use CGI; my $list = new CGI; my $fileDir = "/var/log/vista/stcr2tsvr/"; my @files; print $fileDir; opendir DIR, "$fileDir"; @files = grep(/\.log$/,readdir(DIR)); ## Example file to read 2015 +0210-dubr3psvr-backup.log closedir DIR; print $list->header("text/html"), $list->start_html("Files in $fileDir"), $list->p("These are the files in $fileDir"); foreach my $file (@files) { print $list->p( $list->a({-href=>$file}, $file) ); } print $list->end_html;

I am learning perl and have been able to write several other processes for the web application which is a sysadmin portal for our Linux environment in both perl and BASH scripts. I have seen examples of this code here and on other sites but I can’t seem to figure out what is wrong. Thanks in advance for looking at this and please excuse my ignorance.

Replies are listed 'Best First'.
Re: Display DIR files and output in html to select a file
by poj (Abbot) on Feb 24, 2015 at 20:59 UTC
    Try correcting the first line
    #!/usr/bin/perl ^ add
    poj

      Ughh. Feel so silly. Thanks! So it does display as such: These are the files in /var/log/vista/stcr2tsvr/

      stc-gblkcopy.log 20150208-dubr3psvr-backup.log vista-stc.log 20150209-dubr3psvr-backup.log 20150210-dubr3psvr-backup.log cconsole.log 20150207-dubr3psvr-backup.log
      and they are hyperlinks. Just need to figure out why when I click a link it is looking for the file in the cgi-bin dir where it is not located. So clicking the hyperlink of the log file that is located in /var/log/vista/stcr2tsvr/ directs me to http://10.*.*.*:****/cgi-bin/20150207-dubr3psvr-backup.log. Is there a way to direct it to the proper location or do I need to set up an alias in the httpd.conf pointing to /var/log/vista/stcr2tsvr/

        So this is the portion that I am referencing

        foreach my $file (@files) { print $list->p( $list->a({-href=>$file}, $file) );

        the href is looking for the correct file name just in the wrong DIR looking in cgi-bin. How would I say $list->a({-href=>$fileDir+$file}, So have the href look in the $fileDir and display the $file to read it. I want the href to include the correct DIR+File

Re: Display DIR files and output in html to select a file
by Anonymous Monk on Feb 24, 2015 at 21:16 UTC

      Thanks for the links! I also downloaded a few books to my kindle last night. I have noticed some similarities to Perl and ANSI MUMPS which I use for work for our database environment and have been able to mix it up a little. Thanks again for running this good site!

        So setting the dir. was simple enough

        $list->a({-href=>$fileDir.$file}),

        But I am getting Can not be found even thought it is looking in the proper DIR and the file is there. Can you offer anymore insight to this? Thanks!

Re: Display DIR files and output in html to select a file
by vhaphisasset (Initiate) on Feb 25, 2015 at 20:14 UTC

    Good to Go! I added the following to the httpd.conf:

    Alias /logs/ "/var/log/vista/stcr2tsvr/" <Directory "/var/log/vista/stcr2tsvr/"> Options Indexes MultiViews FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory>

    and changed the code to reflect the alias

    #!/usr/bin/perl use strict; use CGI; my $list = new CGI; my $fileDir = "/var/log/vista/stcr2tsvr/"; my $alias = "/logs/"; my @files; print $fileDir; opendir DIR, "$fileDir"; @files = grep(/\.log$/,readdir(DIR)); ## Example file to read 2015 +0210-dubr3psvr-backup.log closedir DIR; print $list->header("text/html"), $list->start_html("Files in $fileDir"), $list->p("These are the files in $fileDir"); foreach my $file (@files) { print $list->p( $list->a({-href=>$alias.$file}, $file) ); } print $list->end_html;

    Sometimes a simple question as an answer is the means to solving the problem! THANKS POJ!

Re: Display DIR files and output in html to select a file
by Anonymous Monk on Feb 24, 2015 at 20:59 UTC
    "When I call the script from IE ..."

    This is the 21st Century. Please use a browser like Chrome or Firefox.

      Did check in several other browsers ;)