Web Hosting Talk







View Full Version : 'simple' hit counter


amazer
03-27-2004, 09:52 PM
I want to create a simple little hit counter in shell. I figure I will store a value in a file. Read it when the page is accessed using SSI and write a new value over the top. Trouble is, I am useless at scripting. So far what I have is this:

#!/bin/sh
NUM=`cat counter.dat`
let "NUM=$NUM+1"
echo $NUM >> counter.dat

but that seems to be concatenating the file.
How do I overwrite?
Thanks in advance.
Chris.

NyteOwl
03-27-2004, 10:36 PM
#!/bin/sh
NUM=`cat counter.dat`
let "NUM=$NUM+1"
echo $NUM > counter.dat

> is overwrite file >> is concatenate file

amazer
03-27-2004, 11:50 PM
Thankyou. Now that is working fine when I execute the script manually from a terminal window. But it isnt working when I call it through my web???? Its not giving any errors, it just doesnt seem to be writing to the file. Its not to do with refresh as I have checked the datafile.

#!/bin/sh
NUM=`cat ../htdocs/mystuff/counter.dat`
let "NUM=$NUM+1"
echo $NUM > ../htdocs/mystuff/counter.dat

<body>
<b>Welcome to my world!</b><br>
You are visitor number: <br>
<!--#exec cgi="/cgi-bin/counter.cgi" -->
<!--#include file="counter.dat" -->
<!--#config timefmt="%d/%m/%y" -->Today's Date:
<!--#echo var="DATE_LOCAL"--><br>
</body>

IM guessing its something to do with pathnames

dont know how to represent this dir structure here. cgi-bin and htdocs are on the same level.

>cgi-bin dir > counter.cgi
>htdocs dir > my stuff dir > welcome.shtml, counter.dat

amazer
03-28-2004, 03:46 AM
wel problem before was file permissions, now I am getting
"Premature end of script headers: /spare0/csci399/clf02/cgi-bin/counter.cgi"

Check the error logs, duh