Jump to content

Perl Info


oneoleguy

Recommended Posts

Hello I was browsing today and found a site that provided a Perl Info script. When I tried it on my installation of Apache2Triad it didn't work. My guess is that I put it in the wrong directory, but I don't know the correct directory to put it in. I put it in apache2triad\htdocs.This is the script: perlinfo.cgi

#!/usr/bin/perlprint "Content-type: text/html\n\n";#Location of Perl$output = `whereis perl`;@locations = split(" ",$output);foreach $line (@locations) 	{	$whereperl .= "$line<br>";	}#Location of Sendmail$output = `whereis sendmail`;@locations = split(" ",$output);foreach $line (@locations) 	{	$wheresendmail .= "$line<br>";	}#Location of Current Directory$currentdirectory = `pwd`;#Perl Variables$perlversion = $];#Perl Os$perlos = $^O;#Module Pathsforeach $line (@INC) 	{	$modulepaths .= "$line<br>";	}#Environment Variables$environment = qq~<table width="100%" border="1" cellspacing="0" cellpadding="2" bordercolor="#000000"><tr> <td colspan="2" bgcolor="#0033CC"> <div align="center" class="tabletitle">Environment Variables</div></td></tr>~;@allkeys = keys(%ENV);foreach  $key (@allkeys) {$value = $ENV{$key};if ($value eq "") {$value = "-";}$environment .= qq~<tr> <td width="150" class="tableitems">$key</td><td class="tablevalue">$value</td></tr>~;}$environment .= qq~</table>~;$documentroot = $ENV{'DOCUMENT_ROOT'};if ($documentroot ne ""){@lines = `du -c -k $documentroot`;$lastline = @lines-1;($diskusage) = split/[\t| ]/,$lines[$lastline];}#Server Software$serverip = $ENV{'SERVER_ADDR'};$servername = $ENV{'SERVER_NAME'};$serverport = $ENV{'SERVER_PORT'};$serversoftware = $ENV{'SERVER_SOFTWARE'};$serveruptime =`uptime`;#Localtime($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);@months = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");$date = sprintf("%02d-%s-%04d",$mday,$months[$mon],$year+1900);$time = sprintf("%02d:%02d:%02d",$hour,$min,$sec);$localtime = "$date, $time";#GMTtime($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time);@months = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");$date = sprintf("%02d-%s-%04d",$mday,$months[$mon],$year+1900);$time = sprintf("%02d:%02d:%02d",$hour,$min,$sec);$gmttime = "$date, $time";print qq~<html><head><title>Perlonline.com - Perlinfo.cgi</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css"><!--.tabletitle {  font-family: Arial, Helvetica, sans-serif; font-size: 14px; font-weight: bold; background-position: center; color: #FFFFFF}.tableitems {  font-family: Arial, Helvetica, sans-serif; font-size: 12px}.tablevalue {  font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bolder}--></style></head><body bgcolor="#FFFFFF" text="#000000"><table width="100%" border="1" cellpadding="2" cellspacing="0" bordercolor="#000000">  <tr bgcolor="#0033CC"> 	<td colspan="2" class="tabletitle"> 	  <div align="center">Server Information</div>	</td>  </tr>  <tr> 	<td class="tableitems" width="150" valign="top">Name</td>	<td class="tablevalue">$servername</td>  </tr>  <tr> 	<td class="tableitems" width="150" valign="top">IP</td>	<td class="tablevalue">$serverip</td>  </tr>  <tr> 	<td class="tableitems" width="150" valign="top">Listing Port</td>	<td class="tablevalue">$serverport</td>  </tr>  <tr> 	<td class="tableitems" width="150" valign="top">Document Root</td>	<td class="tablevalue">$documentroot</td>  </tr>  <tr>	<td class="tableitems" width="150" valign="top">Disk Usage by Root</td>	<td class="tablevalue">$diskusage Kb</td>  </tr>  <tr> 	<td class="tableitems" width="150" valign="top">Software's Installed</td>	<td class="tablevalue">$serversoftware</td>  </tr></table><br><table width="100%" border="1" cellspacing="0" cellpadding="2" bordercolor="#000000">  <tr bgcolor="#0033CC"> 	<td colspan="2" class="tabletitle"> 	  <div align="center">Perl Information</div>	</td>  </tr>  <tr> 	<td class="tableitems" width="150" valign="top">Perl version</td>	<td class="tablevalue">$perlversion</td>  </tr>  <tr> 	<td class="tableitems" width="150" valign="top">Compiled For</td>	<td class="tablevalue">$perlos</td>  </tr>  <tr> 	<td class="tableitems" width="150" valign="top">Module Paths</td>	<td class="tablevalue">$modulepaths</td>  </tr></table><br><table width="100%" border="1" bordercolor="#000000" cellpadding="2" cellspacing="0">  <tr bgcolor="#0033CC"> 	<td colspan="2" class="tabletitle"> 	  <div align="center">Location of Important Unix Programs</div>	</td>  </tr>  <tr> 	<td class="tableitems" width="150" valign="top">Perl</td>	<td class="tablevalue">$whereperl</td>  </tr>  <tr> 	<td class="tableitems" width="150" valign="top">Sendmail</td>	<td class="tablevalue">$wheresendmail</td>  </tr></table><br><table width="100%" border="1" cellspacing="0" cellpadding="2" bordercolor="#000000">  <tr bgcolor="#0033CC"> 	<td colspan="2" class="tabletitle"> 	  <div align="center">Time</div>	</td>  </tr>  <tr> 	<td class="tableitems" width="150" valign="top">Server Time (Local)</td>	<td class="tablevalue">$localtime</td>  </tr>  <tr> 	<td class="tableitems" width="150" valign="top">Server Time (GMT)</td>	<td class="tablevalue">$gmttime</td>  </tr></table><br>$environment <p align="center" class="tablevalue"> </p><p align="center" class="tablevalue">All rights Reserved 2001. <a href="http://www.perlonline.biz">Perlonline.biz</a></p></body></html>~;

The error message I got was 500. My Command Panel says the path to perl is C:/apache2triad/perl/bin/perl.exe, if that makes any difference.Does anyone know what I'm doing wrong?Bill

Link to comment
Share on other sites

I seem to be the resident Perl Guy, too. 500 is a generic error that just means "Sumpfin broke!" Before or during the interpreting process. (Runtime errors just stop execution, so if you divide by zero or something, the nice HTML you're generating will stop in mid sentence.)Assuming the script is okay there are 2 likely sources of trouble.1. File permissions. Perl scripts, unlike php scripts, need to be set to 755, which is the same as rwx r-x r-x. However you connect to your server, there's gotta be a little panel that will let you change these.2. If you copied and pasted your script from an online source, you got a HEAP of trouble. Also unlike php, Perl is crazy about having the correct end-of-line codes. When you copy off the web, you always get the wrong ones. You're favorite text editor may also use the wrong ones. Hard to tell, because they're invisible.If your script were shorter, I'd say put it into the editor built in to your site's control panel and MANUALLY work your way through the doc and simply delete each end-of-line code and immediately replace it by hitting your return key.ORExperiment with several text editors until you find one that uses the correct newline char AND has a global search and replace function. Find which editor works by typing a 2-line HELLO WORLD program, saving it, changing permissions, and seeing if it runs. If it does, and you like it, THAT's your editor, the one you can trust and forget about. When you've got it, paste your script into it and search for any combination of every combination of \n and \cr and replace each instance with ONE \n. You might get lucky.ORif you know enough php, write a script that will do the above for you. You'll still need to find the right editor for future work, though. I use the one built into an old version of GoLive because it has FTP also. Obviously, if you are sitting at a terminal you'll use emacs or pico or something.When you're writing your own script, the other most likely sources of 500 are missing semicolons and unterminated quotes.This all sounds like insanity, but it's just growing pains and they go away. You just have to think twice about copy and paste.Look into a Perl Module called CARP to give you more runtime feedback on errors.

Link to comment
Share on other sites

I got the script from an online website. It came in a .zip file. I unzipped it and copied it to another directory.I got a similar file on php called: phpinfo.php.The entire content of that file was: <?php phpinfo(); ?> I saw this perlinfo file and thought I'd be getting something similar.I guess I'll just wait until I start studying Perl to see all that Perl has on my PC.Thanks,Bill

Link to comment
Share on other sites

I found another script and tested it as well.It got the same 500 error message under apache.It worked fine in a dos window with the command: perl fstprgm.pl (and .cgi)

#!/usr/bin/perlprint "Hello, World...\n";

Interesting!I am using a text editor (not notepad) named EditPlus. I use it for all my programming and all my scripts have always worked fine.The frstprgm.pl that ran in DOS/Win2000 worked fine but did not run when executed from apache. That kinda' makes me think that something in Apache isn't set-up correctly.Does it have a .ini file?Bill

Link to comment
Share on other sites

Sure your Apache is configured to work with Perl (and that the directory is /usr/bin/perl)?

Link to comment
Share on other sites

I believe Perl ignores the shebang (#!/path/to/perl) when a file is invoked from the command line, so that's no hint at all.Did you check the file permissions? You don't say. A file does not transmit, zipped or otherwise, with permissions. They must be reset.Try this shebang: /usr/local/bin/perlCould be your apache config file is not set up correctly.

Link to comment
Share on other sites

I believe Perl ignores the shebang (#!/path/to/perl) when a file is invoked from the command line, so that's no hint at all.Did you check the file permissions? You don't say. A file does not transmit, zipped or otherwise, with permissions. They must be reset.Try this shebang: /usr/local/bin/perlCould be your apache config file is not set up correctly.
If the shebang is ignored at the command line and the program works, but the shebang isn't ignored in apache and the program doesn't run give a clue that it is the problem.I don't know how to check the permissions on this installation of apache2triad. All the domains I have are on linux (not win2000 like this installation) and they have a file manager from which to change the file permissions. I haven't been able to find one on this apache2triad installation.That shebang didn't work either.I don't know where the apache configuration file is either.Oh, yeah, I'm a real novice at this stuff.Bill
Link to comment
Share on other sites

Hi guys,I've been trying to get this programs to work and have part of my troubles figured out. The program:

#!/usr/bin/perl 				  print "Hello, world";

Didn't work on my apache2triad installation nor did it work on either of my domain hosts (both running linux/apache). I got a different tutorial and found this program:

#!/usr/bin/perl -w				  print "Content-type: text/html\n\n";print "Hello, world";

It did work on my domain hosts servers. It did not work on my apache2triad server.I think the apache2triad (perl portion) has some installation issues!I'm trying to register with the apache2triad forum to ask what the problem is.I'll let you know.Bill

Link to comment
Share on other sites

Yeah, the content type is mandatory for the server, and you need BOTH newlines. Just paste that whole section unless you know in advance you'll need a different header for some of your routines. You had it in your first script so I didn't mention it.-w turns on warnings. Could be helpful or a nuisance. Won't make a broken script run, however. There's a whole llist of compiler directives. -t looks for tainted input data, etc. Good stuff to know.

Link to comment
Share on other sites

Well I think I've found my apache2triad server problem. It is 2 fold.1) the shebang line needs to look like this:

#!C:/apache2triad/perl/bin/perl.exe

and 2) the file extension must be .cgi.When I made these changes, the script worked fine on my apache2triad installation.Thanks for all your help,Bill

Link to comment
Share on other sites

We're getting a lot of questions like this lately. It'd be nice <cough> if SOMEONE could pin us to a set of start-'em-ups for running (U)(Li)nux on a PC. It's just frustrating we can't paste a URL, you know?

Link to comment
Share on other sites

We're getting a lot of questions like this lately. It'd be nice <cough> if SOMEONE could pin us to a set of start-'em-ups for running (U)(Li)nux on a PC. It's just frustrating we can't paste a URL, you know?
Let's see if I can start one, look for my post "The Perl Shebang line"Bill
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...