简体   繁体   English

使用PHP显示Perl脚本的输出

[英]using PHP to display output from a perl script

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. 我是PHP的新手,我有一个可以运行的perl脚本,该脚本基本上登录到远程服务器,管理一个日志文件,并向STDOUT显示某些日志文件信息。

I want to make this now viewable as a web page, hence looking at PHP to display this output. 我现在想使它在网页上可见,因此请看PHP以显示此输出。 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. 同样,任何有关通过PHP格式化输出格式的最佳方法的想法/示例也都很好。 Thanks!! 谢谢!!

Here is the perl script: (executed by passing some arguments) 这是perl脚本:(通过传递一些参数执行)

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);
}

use: exec( "your command (execute perl script)" , $output ); 使用:exec(“您的命令(执行perl脚本)”,$ output);

Data written to stdout should be in $output variable. 写入标准输出的数据应在$ output变量中。 Remeber that http server will be waiting on this command until your script has ended, so be aware of waiting from keyboard input etc. 请记住,http服务器将一直等待此命令,直到脚本结束为止,因此请注意等待键盘输入等。

Just to show the output there's no real need for PHP here. 只是为了显示输出,这里并不需要PHP。 Redirect the Perl output to a file that the web server can serve statically and access that with a browser. 将Perl输出重定向到Web服务器可以静态服务的文件,并使用浏览器访问该文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM