开发者

using PHP to display output from a perl script

开发者 https://www.devze.com 2023-01-08 22:07 出处:网络
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'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/lo开发者_如何学Pythong/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);
}


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消