Title: using PHP to display output from a perl script
Tags: php;perl
Question: 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&gt;) {
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);
Comment: It's perfectly possible to make perl-based websites, too you know! Check out HTML75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0Mason http://www.masonhq.com/


Here is another answer: 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.
Comment for this answer: The static file, the output from the Perl script, must be stored in a place that can be served by the webserver.
Comment for this answer: 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.
Comment for this answer: Or simply call the perl script directly from the web server.

Here is another answer: 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.
Comment for this answer: Thanks @killer_PL. Am i better off then converting this perl script to php then?
Comment for this answer: @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!
Comment for this answer: @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.
Comment for this answer: 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.
Comment for this answer: 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.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 1, 'ContentLicense': 'CC BY-SA 2.5', 'CreationDate': '2010:00:07/27/10', 'FavoriteCount': 1.0, 'PostTypeId': 1, 'Tags': '<php><perl>', 'Title': 'using PHP to display output from a perl script', 'ViewCount': 2967, 'id': 3347216, 'user_AboutMe': '', 'user_AccountId': 157160.0, 'user_DisplayName': 'jdamae', 'user_Reputation': 3829.0, 'user_Views': 199.0, 'user_id': 374916.0}}