tags:

views:

54

answers:

2

I'm new to PHP and I have a working perl script that basically logs into remote servers, cats a log file and displays certain log file information to STDOUT.

I want to make this now viewable as a web page, hence looking at PHP to display this output. I just want to view the same output as I see on the terminal for now. The goal would be then to improve the formatting/presentation of this data.

Also, any ideas/examples on best approach to format the output via PHP would be great. Thanks!!

Here is the perl script: (executed by passing some arguments)

Usage: ./statsinfo.pl Jul 26 2010 /var/log/server.log server1

my($mon,$day,$year,$file,$server) = @ARGV;
my $regex_flag = 0;                 
splice(@ARGV, 0, 4, ());            
foreach my $server ( @ARGV ) {     
    print "===================================================================================\n";
    print "REPORTING SUMMARY for BACKUP SERVER : $server\n"; 
    open(my $fh,"ssh $server cat $file |") or die "can't open log $server:$file: $!\n";
    while (my $line = <$fh>) {
        if ($line =~ m/.* $mon $day \d{2}:\d{2}:\d{2} $year:.*(ERROR:|backup-date=|backup-size=|backup-time=|backup-status)/) {
            print $line;
            $regex_flag=1; 
        }
    } #end while loop
        if ($regex_flag==0) { 
           print "NOTHING TO REPORT FOR $server: $mon $day $year \n";
        }
    $regex_flag=0; 
    close($fh);
}
+3  A: 

use: exec( "your command (execute perl script)" , $output );

Data written to stdout should be in $output variable. Remeber that http server will be waiting on this command until your script has ended, so be aware of waiting from keyboard input etc.

killer_PL
Thanks @killer_PL. Am i better off then converting this perl script to php then?
jda6one9
If your script executes fast, you don't have to do it. In small problems and tools for your usage this is ok. But in larger solutions it's quite good to do it in PHP, especially that this script is simple.At your place, i would rewrite this only if php do not permit exec command on your server.
killer_PL
@jaedre619: You don't need to convert the Perl script to PHP if the script is working OK. Just use it from PHP like Killer_PL suggested.
jmz
@killer_PL, @jmz - the perl script works fine and it is basic. After making this viewable via the web, I would then like to enhance the format/presentation. Is printf the function I would use for this? Thanks guys!
jda6one9
i think, that better way is to output data from perl in non-formatted output (like "x;y;z;....), explode() it in PHP by ";" and do html-tagget output in PHP.
killer_PL
+2  A: 

Just to show the output there's no real need for PHP here. Redirect the Perl output to a file that the web server can serve statically and access that with a browser.

Kwebble
@Kwebble - where would i put the static file? if its a text file can it be read as such or does it have to be called within another php script? thanks.
jda6one9
Or simply call the perl script directly from the web server.
Ether
The static file, the output from the Perl script, must be stored in a place that can be served by the webserver.
Kwebble