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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

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

Status
Not open for further replies.

jbs

Programmer
Feb 19, 2000
121
US
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.<br>
<br>
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).<br>
<br>
Anyway, inside the web file &quot;index.html&quot; I have the following statement:<br>
<br>
&lt;!--#exec cgi=&quot;/cgi-bin/count.cgi&quot;--&gt;<br>
<br>
My understanding is that this statement should activate the perl script called count.cgi which is in the folder cgi-bin.<br>
<br>
File &quot;count.cgi&quot; contains the following:<br>
<br>
#!/usr/bin/perl<br>
print &quot;Content-type: text/html\n\n&quot;;<br>
$file=&quot;count.count&quot; ¦¦ print &quot;Failed to obtain file name $file, $!&lt;BR&gt;\n&quot;;<br>
open (COUNT, &quot;$file&quot;) ¦¦ print &quot;failed to open $file, $!&lt;BR&gt;\n&quot;;<br>
$val = &lt;COUNT&gt;;<br>
$val++;<br>
close (COUNT);<br>
open (OUT, &quot;&gt;$file&quot;) ¦¦ print &quot;faile to open OUT=$file, $!&lt;BR&gt;\n&quot;;<br>
print OUT $val;<br>
close (OUT);<br>
exit;<br>
<br>
The perl script works great when I use the &quot;perl count.cgi&quot; 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.<br>
<br>
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.<br>
<br>
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.<br>
<br>
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?<br>
<br>
thanks,<br>
<br>
Jerry<br>

 
QUESTION 1:<br>
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.<br>
<br>
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.<br>
&lt;!--#exec cmd="some_executable_here" --&gt;<br>
<br>
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, <br>
&lt;!--#exec cgi="server side some_code.cgi" --&gt;<br>
<br>
QUESTION 2:<br>
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.<br>
You can see what environmental vars are available to you in your CGI like,<br>
<br>
foreach $var (keys (%ENV))<br>
{<br>
print "$var, $ENV{$var}\n";<br>
}<br>
<br>
FINALLY,<br>
I can't tell if you are asking the students to submit a form. Are you actually calling some CGI ( as in &lt;FORM action...), or just trying to grab what you can from a static HTML 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.<br>
<br>
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.<br>
<br>
My hope now is that there is another alternative that my ISP has for this type of situation.<br>
<br>
Thanks,<br>
<br>
jerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top