EasyCounter

Last Revised Mar 11, 1998. Modified getdate.txt and custom getdate.txt yield more accurate hit counts. Previously revised, Jul 14,1996
EasyCounter gives you several options for making a counter and displaying it on one or more web pages. The simplest (EasyCounter I), displays the start date of your server's access log and gives your page's cumulative total since then. The display looks like:

Accesses since: 01/Apr/1996: 756

Most ISP's refresh their access logs periodically. Since this counter counts current accesses only, you will lose counter data if the server's access log is restarted with zero. If that doesn't matter to you, use EasyCounter I.

EasyCounter II is significantly more complex, but also much more elegant and useful. It keeps a daily and a cumulative access count and displays both (or just one, if you prefer). The page display looks like:

Page accesses on 26/Apr/1996: 126
Total accesses since July 8,1995: 38873 . This count was last updated on 26/Apr/1996

You can also make a summary html page of accesses to all pages you maintain. This is called mysite.html.

This is my third major revision to EasyCounter. The first was posted November 12, 1995. The second was posted April 27, 1996. The instructions were modified some on July 13, 1996. The third revision was posted March 11, 1998. I hope the insructions are clear, but in truth, EasyCounter II is not really easy to follow. It does work well, however, and it may give you ideas even if you choose not to implement it. I think EasyCounter I is, indeed, easy, and I hope it is for you, as well.

Overview

To use EasyCounter, you need to be able to read your provider's access log. You do not need cgi-bin access. Indeed, I wrote EasyCounter because I do not have cgi-bin access on my server, so I was not able to put one of those cute odometer style counters on my page. I used to use a counter from one of those sites that offers it as a service. But I never found it to be reliable. It also did not count lynx accesses. EasyCounter will count lynx accesses. The only thing you might not like about EasyCounter is that it does not increment with each access. It only shows a new count when you run an EasyCounter script. That's fine with me.

When you use EasyCounter, you will use a shell script that scans your system access log for references to your pages. Once you have completed the counting, you will rebuild your web page(s), placing the counter information at the end. Finally, you will place your rebuilt page in the public_html directory.

If you use EasyCounter II, it will also build a mini access log of accesses to just your html pages (EasyCounter I does not build or use the mini access log).

Once you have built the mini log, you will use it as a database for counting accesses to your html page(s). The mini log makes it easier to keep a cumulative counter. It also lets you generate pages such as mysite.html

EasyCounter II can keep track of accesses to one or more html pages (you can also count non-html pages, but you will have to make some changes to do that. I don't bother, since the only pages I am interested in counting are my html pages).

Disclaimer:There is more than one way to skin a cat, and there may better and more elegant ways to put a hit counter in your page. If you have suggestions for improvements, let me know.

I have tweaked EasyCounter so it works for me. I certainly hope it works for you as well. But, your mileage may differ. Use at your discretion, peril, etc. I have attempted to make these instructions clear enough for non-computer types such as myself to follow. Let me know if they are not.

Nuts and Bolts

There are two counters described. Choose the one that best meets your needs. You need to do the following regardless of which counter you choose.

1. Make a new directory called easycount [mkdir easycount]. The square brackets are for clarity. Do not include them when you type the commands.

2. Change to this directory, [cd easycount], and copy your web page to it. (EasyCounter can count the accesses for more than one html page, but it is easier to explain its operation assuming just one page. You would repeat this process for multiple pages.)

3. If your page (e.g. mypage.html) is in the public_html directory, the command would look like this:

cp /path/to/public_html/mypage.html mypage.html.
Be sure to type your real path and real page file name.

4. Edit mypage.html by deleting the final </body> and </html> tags. (I like Pico, but any editor will do.) These tags should be the last ones on your page.

5. Save the resulting page as mypage_short.htm You will be adding the counter to the end of this web page. Use your page name instead of "mypage."

EasyCounter Options: Choose One

EasyCounter I
This is the easiest counter to build. But, it can seriously overcount accesses, since it will count every instance that your html page appears in the server's access_log, whether or not it was a true hit. Every time you run EasyCounter I, it places the current count on your page. This is fine for placing a counter on just one page, but it has its limitations. Since it doesn't make a mini log, it doesn't really let you track accesses in a systematic way. However, it is simple, and if you follow its logic, the more complicated counter will make more sense. My recommendation is that you use EasyCounter II.
EasyCounter II
Counts daily accesses and keeps a cumulative count. Can count accesses on multiple html pages. Makes a mini log which allows you generate other information about your site accesses. This is the one I actually use.
The EasyCounter I shell script: This script for EasyCounter I counts current html references in your server's access log. This demonstration script adds a counter to a page called example.html. When you use this script, be sure to change "example" to something that reflects your page's title.
Save this script as ezI.scr.
Make it executable [chmod u+x ezI.scr]
Run it by typing ezI at your system's unix prompt.
If it runs to your satisfaction, uncomment the next to last line.
#--------------------- EasyCounter I --------------------------
# Assume you want to add a counter to example.html.
# If you haven't already done so, make a directory called easycount.
# Copy example.html to easycount directory. Edit the file to delete the
# </body></html> tags. Save the resulting file as example_short.htm.
# We will use example_short.htm to re-build example.html. Don't
# forget to change the "example" names to something that reflects
# your html page name.
#
# User defined variables. Enter needed values as indicated.
#
url="http://www.bcpl.lib.md.us/~sandyste/example.html"  # Enter your
                                                        # page url
user=sandyste  # Replace sandyste with your userid as it appears in
               # access_log
logpath="/carl/httpd/logs/access_log"  # Enter your access_log path in
          # place of /carl/httpd/logs/access_log.
pubpath="/$HOME/public_html"  # Enter path to your public_html
          # directory in place of/$HOME/public_html if yours is different. 
page1name=example.html # Replace example.html with your page name
page1=example.html     # Replace example.html with your page name
cp example_short.htm $page1 # Replace "example" with your page.
#
# This ends user defined variables. You should not have to modify rest
# of script.
#
# Next section counts the accesses.
#
echo "Counting accesses to $page1 ....be patient."
grep -c $user/$page1name $logpath > "$page1"_hits
newcount=`cat "$page1"_hits`     
# Adding the access count to the html page.
echo "<br>" >>$page1
echo "Accesses since: " >> $page1
head -1 $logpath | cut -d' ' -f 4 | cut -d'[' -f 2  | cut -d':' -f 1 >>$page1
echo "<b>" >>$page1
echo "$newcount"  >>$page1
echo "</b>" >>$page1
echo "<address>" >>$page1
echo "Access counter by <a href=" >>$page1
echo "\"http://www.bcpl.lib.md.us/~sandyste/ezcount.html\">" >>$page1
echo "<b>EasyCounter</b></a>" >>$page1
echo "</address>" >>$page1
# The following four lines are added to the html file to complete it.
# If you don't want the page url included, comment out the next 3 lines.
echo "<hr>The URL of this page is" >>$page1
echo "$url$page1name" >>$page1
echo "<hr>" >>$page1
echo "</body></html>" >>$page1
# The completed file is copied to example.html in the public_html
# directory. Uncomment the following line when the script works to
# your satisfaction
#cp $page1 "$pubpath"
echo Finished

The file, example_short.htm contains the whole page except for the access data and the ending html tags.

The grep -c command looks for the lines that contain references to your page in the server's log. [-c] indicates we are only counting the lines. EasyCounter will work for you as long as your server's access_log has the following format.

pegasus.rutgers.edu - - [26/Jul/1995:13:52:43 -0400] "GET /~jdoe/mypage.ht
ml HTTP/1.0" 200 2234
This is the common log format. It is probably what you have. To take a peak at your server's log, try this command (use the correct path for your server).
more tail /path/to/httpd/logs/access_log
This should show you the last 10 accesses. If your access_log lines have a different format, EasyCounter will not work unless you modify the grep and cut lines. I believe, however, that many, if not most, access logs follow the above format.
The "echo </body></html> >>page1.html" line will add the ending </body> and </html> tags to the html page. The next to last line will copy the html page to the public_html directory.

Save the shell script as [ezI.scr] or anything else you want.

Make [ezI.scr] executable. At the unix prompt, type

chmod u+x ezI.scr

Test the script by typing [ezI.scr] at the unix prompt. Before you test, be sure

cp $page1 $pubpath
is commented out. This line copies the rebuilt html page to your public_html directory. This will prevent you from messing up your html file in case EasyCounter doesn't work. After running [ezI.scr], take a look at your rebuilt page by typing [more example.html] at the unix prompt. You should see the access data at the end of the page. If everything looks OK, uncomment
cp $page1 $pubpath

EasyCounter II: a more elegant and useful counter

EasyCounter II makes use of a mini log of accesses to your html page(s). This forms a database for further use. Don't worry about the database (mini log) getting too large. No more than one day's worth of accesses are maintained. So unless you are getting tremendously large numbers of accesses, or you have very little disk space on your server, this should not be a problem. If it is, you can always use the "EasyCounter I" approach, which does not build a mini log.

Because of the way EasyCounter II keeps track of cumulative accesses, you need to run the counter script once a day. If you run it more often, the cumulative count will be too high. I run my scripts using an "at" command that I have incorporated directly into the script so it will run itself every day without any intervention from me. I have added at commands to the scripts as needed.

Make a New Directory and Files

Before you actually count accesses, you need to create a directory and some specialized files.

If you have not already done so, make a new directory called easycount [mkdir easycount]. The square brackets are for clarity. Do not include them when you type the commands. Change to this directory [cd easycount]. and copy your web page to it. (EasyCounter can count the accesses for more than one html page, but it is easier to explain its operation assuming just one page.) If your page (e.g. mypage.html) is in the public_html directory, the command would look like this:

cp /path/to/public_html/mypage.html mypage.html.
Here is how it looks in real life on my system:
cp /$HOME/public_html/mypage.html mypage.html
Be sure to type your real path and real page file name. Now edit mypage.html by deleting the final </body> and </html> tags. (I like Pico, but any editor will do.) These tags should be the last ones on your page.
Save the resulting page as mypage_short.htm You will be putting EasyCounter at the end of your web page, as this is easiest. You should now have mypage.html and mypage_short.htm in your easycount directory

Here is a list of the files that you will add to the easycount directory. There are a few other files as well, but they will be added automatically when you run EasyCounter II.

  1. mypage.html. This is a copy of the html page on which you wish to place the counter. Change "mypage" to reflect your html page name (e.g. sandy.html). If you want a counter for another page, place a copy of that page in the easycount directory also. You need to copy each html page for which you want a counter.
  2. mypage_short.htm Change "mypage" to reflect your html page name. You need a separate ...short_htm file for each html page on which you want a counter. Remember, this is the same as the html page except that it lacks the final </body> and </html> tags.
  3. getdate.txt This will be discussed below.
  4. ..html.txt **Note: What you call this depends on the name of your html page. It could be myhtml.txt, fshtml.txt (for fun_stuff.html), or anything else you want. If you want a counter on more than one html page, you need a separate ..html.txt for each page. The naming convention I use is, two or three letters from the html filename, followed by html.txt, e.g sphtml.txt for my school_psych.html page, my2html.txt, my3html.txt, etc..This will be discussed below.
  5. runscripts. This will be discussed below.
  6. makelog. This will be discussed below.

Creating the Files

getdate.txt
Use an editor to make a file called getdate.txt [pico getdate.txt]. Copy the following into getdate.txt. Make the indicated changes to user and path.
#-------------------- getdate.txt (rev. 3/11/97)-----------------------
# getdate.txt is a text file that is used to build getdate, an
# executable file that is part of EasyCounterII.
# getdate creates mylog, a mini access_log of hits to your html
# pages. Run getdate anytime tomorrow, and it will log all the
# accesses you had today. That way, you get a full 24 hours worth of
# accesses (makes it easier to keep the counter).
#
# define variables
#
user=sandys
# replace sandyste with your name as it appears in access log.
#
logpath=/carl/httpd/logs/access_log
# replace /carl.....with path to your server's access log.
#
# You should not have to change anything below.
# Define the variable, getdate, as the current date, in access_log
# format
getdate=`date '+%d/%b/%Y'`
# This next section applies to the getdate shell program. It
# writes lines to it. The getdate program won't actually be
# created until makelog is run, so don't worry about it.
echo "echo Creating mylog....be patient." >>getdate
echo Searching access_log
# The following two lines will search only for hits on html pages.
# Graphics, e.g. gif, jpg are excluded. Only 200 range and 304
# http response codes are searched for. This will exclude
# various non-hits from being counted e.g. 404 not found or
# 302 redirection. Including all the html references will give you
# an erroneously high hit count.
egrep "$yesterday.*$user/.*html...........2..
$yesterday.*$user/.*html...........304" $path >mylog
# Don't care about a spuriously high hit count? Comment out the
# above two lines and uncomment the following line.
#echo "grep $getdate.*$user/.*html $logpath >mylog" >>getda
chmod u+x getdate
# end of script
#-------------------- getdate.txt (rev. 3/11/97)-----------------------
Create a file called myhtml.txt. This file will be used to build myhtml, a similarly named executable shell script that will rebuild your html page with the counter on it. What you call ..html.txt should reflect the name of your html page. Do not call it ..html.txt. In this sample, it is called myhtml.txt. Wherever you see references to "myhtml" you should change them to reflect your html page name. For example, if my page is sandy.html, I would have sandyhtml.txt
You will need to change values for variables in the "user defined variables" section.
#---------------------myhtml.txt-----------------------------------
# We copied mypage.html and then edited the file to delete the
# </body></html> tags. We saved the resulting file as 
# mypage_short.htm. Save your file with a name that reflects your
# html page. Follow the same format used here.
# We will use mypage_short.htm to re-build mypage.html
#
# User defined variables begin here.
# 
start="June 30,1995"  # Enter start date for your counter between 
                      # quotes.
page1name=mypage.html # Replace mypage.html with your page name.
page1=mypage.html # Replace mypage.html with your page name.
cp mypage_short.htm $page1 # Replace mypage_short.htm with what you
                           # called your edited html page.
url="http://www.bcpl.lib.md.us/~sandyste/" # replace with your 
  # partial site url. Follow same format.
pubpath="/$HOME/public_html"  # Enter path to your public_html
          # directory in place of/$HOME/public_html if yours is different.
#
# End of user defined variables section.
#
echo "Checking to see if needed files exist. Will build them if needed." 
if test -s $page1"_total"
  then
    echo $page1"_total exists and contains the value:"
    cat "$page1"_total
    echo "To start counter with a different value, change the number in"
    echo $page1"_total"
  else
    echo creating $page1"_total and initializing counter to 0. To start"
    echo "counter with a different value, change the number in"
    echo $page1"_total"
    echo 0  > $page1"_total"
fi
grep -c $page1name /$HOME/easycount/mylog >"$page1"_newhits
newcount=`cat "$page1"_newhits`
oldcount=`cat "$page1"_total`
cumcount=`expr $newcount + $oldcount`
echo $cumcount >"$page1"_total
# Completing the html page.
echo "<br>" >>$page1
echo "Page accesses on "$yesterday: >>$page1
echo "<b>" >>$page1 >>$page1
echo $newcount >>$page1
echo "</b>" >>$page1 >>$page1
echo "<br>Total accesses since $start: " >>$page1
echo "<b>" >>$page1
echo $cumcount >>$page1
echo "</b>" >>$page1
echo "<br>" >>$page1
echo "<address>" >>$page1
echo "Access counter by <a href=" >>$page1
echo "\"http://www.bcpl.lib.md.us/~sandyste/ezcount.html\">" >>$page1
echo "<b>EasyCounter</b></a>" >>$page1
echo "</address>" >>$page1
# The following four lines are added to the html file to complete it.
echo "<hr>The URL of this page is" >>$page1
echo "$url$page1name" >>$page1
echo "<hr>" >>$page1
echo "</body></html>" >>$page1
# The completed file is copied to the public_html directory.
#cp $page1 "$pubpath"
# Uncomment the above line only after you are sure everything is
# working.
#---------------------myhtml.txt-----------------------------------
Create a file named runscripts. The purpose of runscripts is to hold the various commands you need to get this stuff operating properly. Instead of executing several different commands one at a time, you stick them into runscripts. Then, you just execute runscripts, which will execute all needed commands. This will become clear as we move through the explanations. For now, just put the following lines into runscripts. Then at your unix system prompt,
type chmod u+x runscripts
The purpose of the above line is to make runscripts executable.
# ------------------------runscripts------------------------------
echo "Running runscripts on `date`"
getdate
myhtml
#my2html # If you want to place a counter on other pages, e.g. my2html
#my3html # my3html, you would place the commands in runscripts.
#my_site.scr
# my_site.scr is optional. It will be discussed later.
#at -f runscripts 12:30 am tomorrow
# If you can run at commands on your server, uncomment the above
# line. This is handy for automating your counter. 
# ------------------end runscripts---------------------------------

The makelog Script

Before I move on to the makelog shell script, I need to explain my logic. I update my page counters once a day, at 12:30 AM. I always count the previous day's accesses and ignore today's accesses (which I will count tomorrow). I do it this way because it simpler to deal with a single full day at a time when working with system access logs. I execute runscripts at 12:30am. This causes the counter to run and be placed on my html page. It counts yesterdays accessess. Then, at 1:00am, I execute makelog, which provides a new date for the next day.

The tricky part of this process was figuring out how to count yesterday's accesses. The shell script, makelog, allows you to count yesterday's accesses.

The makelog shell script: Use a text editor to create makelog [pico makelog], and copy this text to it. Make indicated changes to customize for your server and html pages.

#######################################################
# Written by Sandy Steingart April 9 - April 11 1996. #
# Please retain this banner if you use this script.   #
#######################################################
#
# After creating makelog, "chmod u+x makelog" so you
# can run it by typing "makelog" (note: don't type the quotes).
#
# Makelog updates a file called getdate. Getdate  creates  
# mylog, a mini access_log of hits to your html pages 
# getdate will search for yesterday's date. 
#
# makelog also updates ..html (myhtml) which causes a counter to be 
# placed on the html page.  
# A file called runscripts is executed via an at -f command at 12:30 am.
# This starts getdate, ..html and my_site.scr. my_site.scr 
# builds mysite.html which is a summary of accesses to my website.
# my_site.scr and mysite.html are options and will be discussed
# later.
#
# Define the variable, getdate, as the current date, in access_log format
getdate=`date '+%d/%b/%Y'`   
echo yesterday=$getdate >getdate # Gives getdate the date it will
                            # search for in the system access log.
cat getdate.txt >> getdate    # Building getdate by adding text.
# This section updates the files which will put counters on various pages.
# Follow the same format to add a counter to more pages.
# In this example, myhtml is being updated. You need to change this
# to reflect your html pages, e.g. my2html and my2html.txt, my3html 
# and my3html.txt.
#
# updating files
echo yesterday=$getdate >myhtml
cat myhtml.txt >>myhtml
#echo yesterday=$getdate >my2html  # These two lines are to illustrate
#cat my2html.txt >> my2html        # how you could add counters to more
#                                  # than one html page.
# end of updating files.
#
echo "makelog executed for $getdate."
echo "..html and getdate updated."
# Run makelog again tomorrow.
#at -f makelog 1:00 am tomorrow
# Uncomment above line if you can run the at command on your 
# server. I hope you can as this is an excellent way to automate
# the process. If you can't run an at command, you will have to
# remember to run this script every day. That will get old quickly.

Adding Counters to More than One Page

EasyCounter II can place counters on multiple html pages. The example I used above assumed a page named mypage.html. Let us assume you also want a counter on mypage2.html and mypage3.html. In general, you follow the EasyCounter II instructions, creating mypage2_short.html, mypage3_short.html, my2html.txt,and my3html.txt. You also need to add lines to makelog and runscripts (I have sample lines in those files)

Starting It All Up

Make sure makelog, getdate, myhtml (or whatever you named it) and runscripts are executable by typing ls -l at the unix prompt. You should see
-rwx------ at the beginning of the line.
If not, follow this format to make them executable.
chmod u+x makelog
After you have created all the needed files, the first script you should run is makelog. Run makelog by typing makelog. Before you run runscripts, open yesterdate and any ..html files you have in runscripts. The first line should say
yesterday=27/Apr/1996
The actual date will be the date you do this. Change the date to yesterday's date and save the files. For the above example, I would change it to
yesterday=26/Apr/1996
Now run runscripts by typing runscripts. That's it. If you can use the "at -f" command I placed at the end of makelog and runscripts, be sure those lines are uncommented. With the at -f command in place, runscripts and makelog will restart themselves at 12:30 and 1:00 am respectively.

mysite.html: Creating a Site Summary Page

If you like the summary in mysite.html, here's the script I used to make it.
#----------------------my_site.scr-----------------------------------
# When executed, this shell script will summarize yesterday's hits for my 
# site.
# /carl/httpd/logs/access_log  is the path to the system access log.
# However, I have a mini access_log of hits on my site at mylog.
# I can count hits on any number of pages.
#
echo "<html><head>" >mysite.html 
echo "<title>Site Stats for Sandy Steingart</title>" >>mysite.html 
echo "</head>" >> mysite.html
echo '<body>' >mysite.html
echo '<h2 align=center>Site Statistics for Sandy Steingart</h2>' >>mysite.html 
echo "<hr>" >>mysite.html 
echo "Summary of accesses to web site.<br> Page generated `date`." >>mysite.html
echo "Statistics for previous day are reported." >>mysite.html
page1=school_psych.html # Replace school_psych.html with your page name
page2=p_01.html
page3=p_02.html
page4=p_03.html
page5=p_index.html
page6=ezcount.html
page7=cholent.html
page8=mental_health.html
page9=fun_stuff.html
path="mylog" # replace what is between quotes with path
                                   # to your access_log
pubpath="/$HOME/public_html" # Be sure path to your public_html directory
                             # is here.
pagename1="<a href="http://www.bcpl.lib.md.us/~sandyste/school_psych.html">School Psychology Resources Online</a>"
#pagename1="School Psychology Resources Online"
pagename2="Specific Disorders"
pagename3="Other Resources"
pagename4="What's New"
pagename5="School Psych Index"
pagename6="EZCount"
pagename7="Cholent Corner"
pagename8="Baltimore Area Mental Health"
pagename9="Fun Stuff"
echo "<ul>" >>mysite.html 
echo "<li>" >>mysite.html 
echo "$pagename1:" `grep -c $page1 $path`  >>mysite.html 
echo "<li>" >>mysite.html 
echo "$pagename2:" `grep -c $page2 $path`  >>mysite.html
echo "<li>" >>mysite.html
echo "$pagename3:" `grep -c $page3 $path`  >>mysite.html
echo "<li>" >>mysite.html
echo "$pagename4:" `grep -c $page4 $path`  >>mysite.html
echo "<li>" >>mysite.html
echo "$pagename5:" `grep -c $page5 $path`  >>mysite.html
echo "<li>" >>mysite.html
echo "$pagename6:" `grep -c $page6 $path`  >>mysite.html
echo "<li>" >>mysite.html
echo "$pagename7:" `grep -c $page7 $path`  >>mysite.html
echo "<li>" >>mysite.html
echo "$pagename8:" `grep -c $page8 $path`  >>mysite.html
echo "<li>" >>mysite.html
echo "$pagename9:" `grep -c $page9 $path`  >>mysite.html
echo "</ul>" >>mysite.html
echo "<hr>" >>mysite.html
echo "<h4>Visitors to School Psychology Resources Online</h4>" >>mysite.html
echo "<pre>" >>mysite.html
echo "`grep school_psych.html mylog | cut -f1, -d' ' | uniq `" >>mysite.html 
echo "</pre>" >>mysite.html
echo "<h4> Visitors to Fun Stuff</h4>" >>mysite.html
echo "<pre>" >>mysite.html
echo "`grep fun_stuff.html mylog | cut -f1, -d' ' | uniq `" >>mysite.html 
echo "</pre>" >>mysite.html
echo "<hr>" >>mysite.html
echo "</body></html>" >>mysite.html
cp mysite.html $pubpath
echo "my_site.scr executed. Site statistics summary page generated."
#------------------------------my_site.scr--------------------------

A Bonus getdate.txt Variation

On my site's server, the access log is refreshed every month. The old access_log is moved to access_log.0 and the new access_log is started with no entries. To handle this situation, I use a slightly different version of getdate.txt than is posted above. This version is unique to my situation. If you encounter something similar on your server, it may give you some ideas as to how you can adapt the basic script to meed your needs.
#------------------ custom getdate.txt (rev. 3/11/98) ---------------------
# getdate creates mylog, a mini access_log for my html pages.
# This version is cutomized for bcpl.net
# It searches access_log and access_log0
# Check for mylog and remove it if it exists.
if [ -r mylog 
  then
     rm mylog
     echo "Old mylog deleted"
  else
     echo "mylog does not exist"
fi
path=/carl/httpd/logs/access_log   # path to current access log.
path0=/carl/httpd/logs/access_log.0  # path to old access log.
user=sandyste    # username as it appears in access log.
echo Creating mylog....be patient
echo Searching access_log and access_log.0
egrep "$yesterday.*$user/.*html...........2..
$yesterday.*$user/.*html...........304" $path >mylog
egrep "$yesterday.*$user/.*html...........2..
$yesterday.*$user/.*html...........304" $path0 >>mylog
#---------------end custom getdate.txt (rev. 3/11/98) ---------------------

EasyCounter I Variation (EasyCounter Ia)

What follows is a script that will keep a cumulative access count without the necessity of building a mini access log. This was written specifically for my site, although with changes to the way my ISP maintains access logs, it won't run properly "as is". It is provided here to give you ideas that you are welcome to use if they are useful to you. If you use something like this, I urge you to run it via a cron file, if you can. Since it searches the entire access log, it runs quite slowly. I don't use it. I prefer EasyCounter II. But, it was interesting figuring out the logic of making a cumulative counter even when the system access log was restarted with zero entries. This will not be as accurate as EasyCounter II and may seriously over estimate your hits.
#--------------------- EasyCounter Ia --------------------------
# Assume you want to add a counter to example.html.
# If you haven't already done so, make a directory called easycount.
# Copy example.html to easycount directory. Edit the file to delete the
# final </body> and </html> tags. Save the resulting file 
# as example_short.htm.
# We will use example_short.htm to re-build example.html. Don't
# forget to change the "example" names to something that reflects
# your html page name. This is not a speedy counter, so be patient when
# you run it. You might want to run this as a cron file. See a unix book 
# for instruction on how to do that. Once you are sure this works,
# uncomment the next to the last line in order to copy your web page to
# your public_html directory.
#
# User defined variables. Enter needed values as indicated.
#
start="June 8, 1995" # Enter starting date for your counter.
url="http://www.bcpl.lib.md.us/~sandyste/example.html"  # Enter your
                                                        # page url
user=sandyste  # Replace sandyste with your userid as it appears in
               # access_log
pubpath="/$HOME/public_html"  # Enter path to your public_html
          # directory in place of/$HOME/public_html if yours is different. 
page1name=example.html # Replace example.html with your page name
page1=example.html     # Replace example.html with your page name
cp example_short.htm $page1 # Replace "example" with your page name.
#
# This ends user defined variables. You should not have to modify rest
# of script.


daymo=`date '+%d'`  # the current day of the month, e.g. 01, 10, etc.
path=/carl/httpd/logs/access_log     # path to current access log.
path0=/carl/httpd/logs/access_log.0  # path to old access log.
echo Checking logs....be patient.
if [ $daymo -eq 01 ] 
  then
    if test -f ranit # This is an indicator file. Tells us if we ran this.
      then
        echo "already ran this at least once today (first of month) so"
        echo "no need to search access_log.0 again."
        grep -c $user/$page1name $path >newcount
      else
        echo "Running script for first time today (first of month). Will"
        echo "search access_log.0 and access_log and update cum. count"
        cat oldcount >oldoldcount
        grep -c $user/$page1name $path0 >oldcount
        ooc=`cat oldoldcount`
        ocnt=`cat oldcount`
        newoc=`expr $ooc + $ocnt`
        rm oldcount          
        echo $newoc >oldcount
        echo "Searching access_log"
        grep -c $user/$page1name $path >newcount
        echo "ran it" >ranit # Creating the indicator file.
    fi
  else  # Section below runs every day except first of month.
    echo "Today is not the first of month. Searching access_log"
    grep -c $user/$page1name $path >newcount
    rm ranit
fi
echo "Checking to see if oldcount file exists. Will build it if needed." 
if test -s oldcount
  then
    echo "oldcount exists and contains the value:"
    cat oldcount
    echo "To start counter with a different value, change the number in"
    echo "oldcount."
  else
    echo "building oldcount and initializing it to 0. To start with a"
    echo "different value, change the number in oldcount"
    echo 0  > oldcount
fi

# updating the cumulative count
oc=`cat oldcount`
nc=`cat newcount`
cumcount=`expr $oc + $nc`

# Adding the access count to the html page.
echo "<br>" >>$page1
echo "Accesses since "$start": " >> $page1
echo "<b>" >>$page1
echo "$cumcount"  >>$page1
echo "</b>" >>$page1
echo "<address>" >>$page1
echo "Access counter by <a href=" >>$page1
echo "\"http://www.bcpl.lib.md.us/~sandyste/ezcount.html\">" >>$page1
echo "<b>EasyCounter</b></a>" >>$page1
echo "</address>" >>$page1
# The following four lines are added to the html file to complete it.
# If you don't want the page url included, comment out the next 3 lines.
echo "<hr>The URL of this page is" >>$page1
echo "$url" >>$page1
echo "<hr>" >>$page1
echo "</body></html>" >>$page1
# The completed file is copied to example.html in the public_html
# directory. Uncomment the following line when the script works to
# your satisfaction
#cp $page1 "$pubpath"
echo "Finished. Check web page for counter."
#--------------------- EasyCounter Ia --------------------------
Major changes Mar 11, 1998, Apr. 24, 1996. Comments to Sandra Steingart
sandyste@umd5.umd.edu
Page accesses on 08/May/2008: 21
Total accesses since April 22, 1996: 256506 This count was updated on 08/May/2008:
Access counter by EasyCounter

The URL of this page is http://www.bcpl.lib.md.us/~sandyste/ezcount.html