Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can print a Unix command output on page?

Status
Not open for further replies.

ozi403

Technical User
Joined
Apr 29, 2002
Messages
54
Location
TR
Hi,

I try to print a Unix command output on page with perl.
My script like this:

#!/usr/local/bin/perl

print "Content-type: text/html\n\n";
print "<html>\n";
print "<body>\n";
print "<p><h2>DENEME</h2>\n\n";


@tut=`rsh bcksrv7 mminfo -a|head -20`;
#@tut = system("rsh bcksrv7 mminfo -a|head -20");
#print "<p><h2>@tut</h2>\n";

print "<@tut>";

print "</body></html>";
exit;

but not print the output on page!Help!

 
Code:
print "<@tut>";
should read
Code:
foreach (@tut) {
   print "$_<br>\n";
}

HTH
--Paul


cigless ...
 
ok I add your code but no output on page.
I run it on Unix, it is working but not print to page.
 
are you looking at this page through a browser
--Paul

cigless ...
 
Try
Code:
#!/usr/local/bin/perl
use strict;
use warnings;
                                       
print "Content-type: text/html\n\n";             
print "<html>\n";                                
print "<body>\n";                                
print "<p><h2>DENEME</h2>\n\n";                  
                                                 
my @tut = qx[rsh bcksrv7 mminfo -a|head -20];           

print join("<br>\n",@tut), "\n";
print "</body></html>";                          
exit;
 
I think html doesn't understand the variable.
Because it prints blank.
 
When you run on the server, does it have authority/permission to run rsh bcksrv7 mminfo -a | head -20? This could account for the empty array.
 
Good point, Steve. You could try ...
Code:
@tut=`rsh bcksrv7 mminfo -a|head -20 [red]2>&1[/red]`;
That'll send any error messages to the same place as the normal output ([tt]@tut[/tt], in this case) so you should see them on your HTML page.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Will this capture the STDERR from the first process in the pipe, or from the head? I'm assuming anyone has permission to run head...
 
Oh! Sorry I was late,

It isn't working Chris.
But I found a different way ;
When I am directing the output to a file then it prints the file.
It doesn't print the variable directly.

Thanks everybody.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top