Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Problem starting a Perl script from #exec directive in a web page

Problem starting a Perl script from #exec directive in a web page

Problem starting a Perl script from #exec directive in a web page

I'm teaching a course to 7th and 8th graders. I sent out homework assignments over the web. I'm in the process of learning Perl and could use a little help....again.

I'm writing my own web visit counter which runs behind the scene away for user visability. I know there are several counters available that are already written, but I'm just trying to learn Perl (...learn by doing, except in this case I need some help).

Anyway, inside the web file "index.html" I have the following statement:

<!--#exec cgi="/cgi-bin/count.cgi"-->

My understanding is that this statement should activate the perl script called count.cgi which is in the folder cgi-bin.

File "count.cgi" contains the following:

print "Content-type: text/html\n\n";
$file="count.count" ¦¦ print "Failed to obtain file name $file, $!<BR>\n";
open (COUNT, "$file") ¦¦ print "failed to open $file, $!<BR>\n";
$val = <COUNT>;
close (COUNT);
open (OUT, ">$file") ¦¦ print "faile to open OUT=$file, $!<BR>\n";
print OUT $val;
close (OUT);

The perl script works great when I use the "perl count.cgi" command; however it doesn't work at all via the web. Permissions have been set fine for the file count.cgi and count.count which contains the counter.

I suspect that the count.cgi script is never actually running because of a linkage problem between the #exec command within the webpage and the script on the server.

Question #1: Anyone have a guess or can guide me in the right direction? I've tried many different configurations of the #exec command....nothing seems to work.

question #2: After incrementing the value of the number in file count.count; I'd like to append a line at the bottom of a separate file which contains detailed data about each student access to the file. I'd like to mark the date, time, and other easy-to-obtain student data and append the information in a single line at the bottom of a file (i.e. create a transaction file for each access). Any ideas?



RE: Problem starting a Perl script from #exec directive in a web page

Be sure that your web server is allowing SSIs and that the 'exec', specifically, is enabled. If you are not the sysadmin, you will likely need to ask the sysadmin about this. Be sure the cgi script has the execute bit set so that the HTTP daemon can use it. Be sure the file 'count.count' has permissions so that the HTTP daemon can write it. Ask here if you are unsure about this.

Then, it appears that you are not sending any info back to the browser, on purpose (at least not from this 'exec' call). That being the case, you do not need to print 'Content-type: text/html\n\n' or anything else to the browser. Just use the 'cmd' flavor of the SSI exec.
<!--#exec cmd="some_executable_here" -->

If, for some reason you need to do it as a CGI and send stuff to the browser, then be sure you are using the correct syntax for whatever web server your on. Something like,
<!--#exec cgi="server side some_code.cgi" -->

Depending on how your students are getting to the page, you may or may not have consistent student info available. If your students are using dial-up internet access to get to the page, then their IP addresses will not be the same each time. You can get REMOTE_ADDR, the IP of the user, and REMOTE_HOST, the name of the remote machine, but it will not uniquely and consistently identify the student or anyone else who is looking at your page. The REMOTE_HOST will look like their ISP. To be sure of who is using your page, you will need to implement some sort of login to your CGI stuff. That is not hard, just would need doing.
You can see what environmental vars are available to you in your CGI like,

foreach $var (keys (%ENV))
print "$var, $ENV{$var}\n";

I can't tell if you are asking the students to submit a form. Are you actually calling some CGI ( as in <FORM action...), or just trying to grab what you can from a static HTML page?

RE: Problem starting a Perl script from #exec directive in a web page

Well, you hit the nail on the head first time. Turns out my ISP has the exec command not enabled. The sysadmin guy said he would get back to me later with another solution.

After spending hours on the problem, I never would have known that the 'exec' command was an option that could be either enabled or disabled.

My hope now is that there is another alternative that my ISP has for this type of situation.



Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close