counting the number of visitor to script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting counting the number of visitor to script
# 1  
Old 03-29-2012
counting the number of visitor to script

I need to write script, counting the number of visitor to this script. help me please!

Moderator's Comments:
Mod Comment Code tags for code, please.

Last edited by numeracy; 03-29-2012 at 04:05 PM..
# 2  
Old 03-29-2012
Every time the program is called, it's a fresh new instance with no memory of previous times it was called. If you want it to remember, it's going to have to store it somewhere, be it in a database or a file.

A database would be ideal since it would solve any worries about two things trying to access the same file at the same time. You could also ad-hoc something to prevent two programs using the same file at the same time, like this:

Code:
#!/bin/bash
MAXTRIES=10
TRIES=0
COUNT=0

# mkfifo will fail whenever something else is already using the count file
while ! mkfifo /tmp/count-fifo 2>/dev/null
do
        sleep 0.1
        ((TRIES++))
        # 'internal server error' if we can't create the fifo
        [ "$TRIES" -ge "$MAXTRIES" ] && exit 1
done

# If we made it this far, we have the fifo.

# Read the last count, if there is one.
[ -f /tmp/count ] && read COUNT < /tmp/count

# Increment it.
((COUNT++))

# Write COUNT to the file
echo "$COUNT" > /tmp/count

# Delete the fifo, letting other things use the file.
rm /tmp/count-fifo

echo 'content-type: text/html'
echo
echo 'script Counter<br>'
echo "Count is $COUNT"



exit 0


Last edited by Corona688; 03-29-2012 at 03:13 PM..
These 2 Users Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help: Counting values less than a number

So I have several files (35000, to be exact) in the format rmsd_protein_*.dat each with 2 columns and 35000 rows. I would like to count how many values in the second column are less than 3 for each file, and output it into a new file so that it ultimately appears as: 1 14057 2 ... (12 Replies)
Discussion started by: Alexandryne
12 Replies

2. Shell Programming and Scripting

Counting a consecutive number in column 2

Hi, I have a input file which contains following data 0 1 0 2 0 3 0 4 0 8 0 9 0 11 1 1 1 2 1 6 1 7 1 8 1 9 2 1 2 11 2 12 (12 Replies)
Discussion started by: Ryan Kim
12 Replies

3. Shell Programming and Scripting

Counting the number of element in each column

Hello, I have a file as follows: ENSGALG00000000189 ENSGALG00000000189 ENSGALG00000000189 ENSGALG00000000215 ENSGALG00000000215 ENSGALG00000000218 ... (5 Replies)
Discussion started by: Homa
5 Replies

4. Shell Programming and Scripting

Counting the number of characters

Hi all, Can someone help me in getting the following o/p I/p:... (7 Replies)
Discussion started by: Sri3001
7 Replies

5. Shell Programming and Scripting

counting number of sentence

Hi all I want to count total numbers of sentences separated by fullstop (.) in different files under a directory at one go. Any help is appreciated. (3 Replies)
Discussion started by: my_Perl
3 Replies

6. Shell Programming and Scripting

counting the number of occurences

say i've got a text file with >10million sequences: ssss ssss tttttt uuuuuu uuuuuu uuuuuu ... I'd like to convert the file so that the output will report the number of occurence right by each sequence: 2 ssss 2 ssss 1 tttttt 3 uuuuuu 3 uuuuuu 3 uuuuuu .... (3 Replies)
Discussion started by: johjoh
3 Replies

7. Shell Programming and Scripting

counting the number of lines - again

Hi all, I use bash shell and I have a problem with wc. I would like to determine the number of lines in a file so I do wc -l filename but I don't want to get the filename again I just would like to have the number of lines and use it in a variable. Can anybody help? Thank you, (7 Replies)
Discussion started by: f_o_555
7 Replies

8. Shell Programming and Scripting

Counting the number of pipes in line

Hi, I'm using the ksh shell. The scenario: I have a couple of directories /home/fd /home/fd/prsd home/fd/stg now i have number of files in each of these directories. some of the files are zipped using gzip so their extension is .gz the content of the files is as follows ... (4 Replies)
Discussion started by: nirnay_s
4 Replies

9. UNIX for Dummies Questions & Answers

Counting number of occurences

Hi All, I have to count the number of occurences of the character " ; " in a given line. I had used the following awk command to achieve the same echo $KOP.dat|awk '{split($1,my,";"); for(i in my)c++ }END{print c-1}' My file KOP.dat had the following data ... (1 Reply)
Discussion started by: kingofprussia
1 Replies

10. Linux

counting the number of lines

Hello, I have afile which begins with a few urls on multiple lines and then there is listing of some information on separate lines. The listing begins with the word Name on a given line followed by teh actual list. I want to count the number of lines in this file after the line having... (6 Replies)
Discussion started by: nayeemmz
6 Replies
Login or Register to Ask a Question