Results 1 to 4 of 4
  1. #1

    'simple' hit counter

    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:

    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.

  2. #2
    Join Date
    Jul 2001
    NUM=`cat counter.dat`
    let "NUM=$NUM+1"
    echo $NUM > counter.dat

    > is overwrite file >> is concatenate file
    "Obsolesence is just a lack of imagination."

  3. #3
    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.

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

    <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>

    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

  4. #4
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts