• Announcements

    • boen_robot

      Guidelines and Netiquette   03/28/2017

      Posting Problems:   Having problems posting your topic? Read through this: To join, you agree to our terms and conditions and fill out and submit a registration form. An activation email will be sent to your email adress, so you'll need to verify your account. After that the account has to be validated by one of the moderators. This will mean that it can take up to a day to be activated. A couple of things to remember to ensure approval: Don't use an email address in one of those $2 four character .com domains eg. xyds.com. These will be deleted and the domain added to the banned list. Don't use an email address that is within a domain with a bad reputation for spam. A Google search is run on every email address and email domain. Don't sign up with an email address that doesn't exist, doesn't work or requires the sender to answer a quiz before their email can get to you. Put your country and or state and city in the signup form. Blank forms will go to the botton of the "to do" list. And make sure that your email address and your country match, saying you're from Alabama and using a .ru email address is not going to get you activated. After a membership is activated the first few posts will be monitored. Posting spam or unapproved topics described in the agreement results in an immediate ban. The email provider and the IP addresses associated with the account will be banned and all posts will be deleted. These strict measures have been deemed necessary to hinder spam. Sorry for any inconvenience this causes, but it's not liable to change. If, after reading this, you still can't post and don't understand why, contact one of the Moderators listed here.   Topic Guidelines   Including the following information can expedite an accurate response from board members: Must be a Specific Problem or Question related to web design and development Include Code in Question (wrap with   for small blocks of code and for longer blocks   ) Include Code Author Include Extra Notes/Modifications/Attempts Include web link to page/file when possible Content Guidelines   You may not post, upload, link to, or email any Content that contains, promotes, gives instruction about, or provides prohibited Content. Prohibited Content includes any Content that breaks any local, state, county, national or international law. Prohibited Content also includes: No direct or indirect advertising or websites, forums, products, services No hijacking of posts (do not post your question in someone elses) Content that infringes upon any rights [ex. MP3s and ROMs] (including, but not limited to, copyrights and trademarks) Abusive, threatening, defamatory, racist, or obscene Viruses or any other harmful computer software False Information or libel Spam, chain letters, or Pyramid schemes Gambling or Illicit drugs Terrorism Hacking or cheating for internet/online games Warez, Roms, CD-Keys, Cracks, Passwords, or Serial Numbers Pornography, nudity, or sexual material of any kind Excessive profanity Invasive of privacy or impersonation of any person/entity Hacking materials or information Posting Tips   There are more BBcodes than there are buttons for on the reply menu. To get the full list, click "BB Code Help" underneath the clickable smilie face menu. Use   for small snippets of code Use   for lengthy snippets of code Use   if your snippet is HTML (optional) Use   if your snippet is SQL (optional) Rules of Conduct   Be nice. There's no need for calling someone stupid if they ask an 'easy' question. Keep your avatars and signatures absolutely child friendly. We have a younger audience on this forum. Keep your language appropriate for the same reason above. Do not PM moderators for help on the forum. Post on the topic, or create a new one.   Spam:   Recently, as you have all without doubt noticed, we have had lots of spam and advertisement on the forum. Therefore, we'd like to alert you as to what to do when you have found any of the aforementioned annoying messages: it. Immediately. Give a clear reason, please, if the advertising is not evident. DO NOT POST! Report, let the post stay as is, and we will get to it, meanwhile if you continue to post as normal in the other threads, it won't be on the top so long. Refrain from PMing the member. This won't help at all, as they are most likely spambots anyway. Thank you.       Images in signatures:   After thinking of users on dial-up, we have decided to enforce the following rules regarding signatures. Please pay heed to them. Respecting these rules is respecting the members on this forum with dial-up. Signature rules: No animated images AT ALL. No matter the amount of animation. Maximum image widthxheight: 300x150 Maximum image (file) size: 15kb Use calm colors. Do not use highly contrasting images in your signature, as this can get really annoying when seeing several posts from one member in the same thread. The same prohibited content goes for images as for posts. Lastly, use common sense. No lengthy signatures please. Save us some scrolling. Thank you.       Links in signatures:   Please understand that w3schools.com only exists because of voluntary work and is barely supported by the advertising littered throughout the tutorials and the forum. So, please, stop advertising other sites. DO not post links that drive traffic away from the w3schools domain - especially to a site that offers similar if not identical information. Please help support the site by keeping individuals on it. Thank you. Here are some guidelines as to what you can put in your signature: w3schools links --> allowed w3.org links --> allowed browser links --> allowed html editor links --> allowed personal sites --> allowed tutorial sites competing with w3schools --> NOT allowed sites completely irrelevant to webprogramming and this forum --> NOT allowed   Thanks for understanding, and for taking the time to read this. ~W3Schools Modstaff~
oneoleguy

Perl Info

12 posts in this topic

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

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now