problems with perl script executing at all

Status
Not open for further replies.

sollerti

New Member
Messages
26
Reaction score
0
Points
0
I have a simple perl script that works fine in other servers. I have tried several things to make it work, but it does not seem to react. Let me try to explain how I have it set up and maybe one of you has some insight or an idea on how to make it work.

perl script starts with
#!/usr/bin/perl

I am calling the script from my public_html foler (directly from the web)
inside index.html

I am using the following command inside index.html:
<!--#exec cmd="cgi-bin/hitcounter.pl page_index"-->

I have tried putting "hitcounter.pl" both directly under public_html and under cgi-bin
I have set hitcounter.pl with 755 permissions

The file that I am writting to is inside: public_html/private/
the name of the file is count.txt
I have also set this file to have 755 permissions

My thoughts:
maybe I should not have it in the cgi-bin directory
maybe I have something in my .htaccess that does not allow perl scripts to run?
should I rename from hitcounter.pl to hitcounter.cgi?
I am using relative paths to tell the programs where to find things:
- inside hitcounter.pl, I have the relative path "../private/count.txt" to find the count.txt file (of course when the hitcounter.pl file is inside the cgi-bin directory
- inside the index.html file I have the path "cgi-bin/hitcounter.pl" referenced

The count.txt file was created directly inside cPanel and named as such

At any rate, any help or ideas would be greatly appreciated.

Thanks!

Edit:

I have been searching on the internet, and I am wondering.

Is it possible to include the following line in an html file on this server?
<!--#exec cmd="cgi-bin/hitcounter.pl -summary"-->

Note de cmd instead of cgi
The reason for this is because I am passing in "-summary" as a variable into the command hitcounter.pl

Questions?
- Can I pass in such variables if I use the cgi instead of cmd exec type?
- Does the cmd exec type work?
- If it does work, does it work inside cgi-bin or should I put it inside another directory?

At any rate, thanks for any help you can provide!

Edit:

Hi,

I think I figured out another step in the puzzle. It seems that unless the file the SSI code is in has an extension of ".shtml" the server just does not process it...

So now, when I have
<!--#exec cmd="cgi-bin/hitcounter.pl -summary"-->

inside an .html file and I check the source code from a web browser, the above line still shows
instead if the extension is .shtml, the code above does not show

nevertheless, it does not seem like the code inside hitcounter.pl runs anyhow. It seems like the SSI code is recognized, but either not run or for some reason I might have some typo somewhere...

Any further ideas?

Thanks!

Edit:

One more input after searching the web for answers -- maybe the system administrator can answer this one...

is it possible to do SSI of the type <!--#exec cmd= ??

if so, what are the restrictions or conditions, if any.
Do I need to set something specific or special in the .htaccess file, (e.g. <limit > allow,deny -- or something of the sort?)

Thanks!
 
Last edited by a moderator:

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Have you tested whether or not hitcounter.pl works on its own? What do you get if you access it directly from a browser?

I doubt the exec cmd command is enabled, considering that the equivalent is disabled everywhere else. Try include virtual and exec cgi (the former is preferred), and make sure you use the correct path (relative paths are relative to the including document).
 
Last edited:

sollerti

New Member
Messages
26
Reaction score
0
Points
0
Thanks for your follow-up misson!

I tried hitcounter.pl directly from a web browser and it gives me a 500 Error.

The script behind hitcounter.pl uses a variable behind it (either page_name or -summary) so the full command would look like:
hitcounter.pl index, or hitcounter.pl -summary,
or anything of the sort

The script then opens a text file and increases the count of that page, or shows a summary of all the pages

So basically this script has no interaction (at least when the -summary is not requested) with the web browser, it should all happen behind the scenes, which is why I was using the "exec cmd" instead of "exec cgi"

I tried using "include virtual" but I am not sure whether it accepts a variable behind it (i.e. hitcounter.pl -summary)

I am not really including anything into an HTML file. I just want to run a very very simple program behind the scenes to update the page count of all my pages in the same text file and then be able to show a summary of this when requested.

Any further thoughts?
Thanks!

Edit:

Hi Misson!

One question that might (just might) solve my problem...if I use cgi instead of cmd on the exec line (of course praying that cgi is enabled)...

I have the following line in my perl script:
$param=shift @ARGV

which reads in the arguments from the "command line" and stores them in $param

what is the syntax inside the html file if I use cgi? For example...
<!--#exec cgi="cgi-bin/hitcounter.pl -summary"--> or maybe
<!--#exec cmd="cgi-bin/hitcounter.pl?-summary"--> or some other syntax

and also what would the syntax replacing $param=shift @ARGV be inside the perl script to read the parameter behind the "?"

Thank you!

Edit:

OK I think I have figured out how to fix my issue (this thread can be closed now)

I am going to try to explain for completness how I fixed my problem.

I wanted to use a perl script over SSI and not through CGI, so I wanted to use one of the following three ways of executing my script from inside an .html file:
1) <!--#exec cmd="/cgi-bin/hitcounter.pl page_name"-->
2) <!--#exec cgi="/cgi-bin/hitcounter.pl"-->
3) <!--#include virtual="/cgi-bin/hitcounter.pl?param=page_name"-->

1) does not seem to work, probably "IncludesNoExec" is enabled
2) probably works, but it definitely does not work if you want to pass in a paramenter (which I did)
3) works fine, but with some issues which I explain below:
- first, since it is an include, it actually tries to include something into the html file...since I did not want any kind of print to screen, I simply wrote:
Code:
print "Content-type: text/html\r\n\r\n";
and that solved it

- second, for anything of this to work, since it is an SSI, you need to rename your html file to .shtml, another option is to put
AddHandler server-parsed .html
into your .htaccess file

- third, now that you have all this running, you need to put your perl script in the CGI directory (maybe it works from another location, but it definitely works from the cgi-bin directory)

- inside the perl script I needed the following code in order to read the parameters:
Code:
if (length ($ENV{'QUERY_STRING'}) > 0){
      $buffer = $ENV{'QUERY_STRING'};
      @pairs = split(/&/, $buffer);
      foreach $pair (@pairs){
           ($name, $value) = split(/=/, $pair);
           $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
           $in{$name} = $value; 
      }
}
$param = $in{'param'};
with the above you are ready to go, since you can run the script from any web page, read the parameters into the script, and the script is not upset because you make it print something which ends up not bothering your original page layout.

Thanks Misson for your help!
 
Last edited by a moderator:

Zubair

Community Leader
Community Support
Messages
8,766
Reaction score
305
Points
83
This is not the right section for this topic

***Moved to Programming Help***
 
Status
Not open for further replies.
Top