Forum Moderators: coopster & phranque

Message Too Old, No Replies

cron job, parse script, lock directory

can anyone help me write a simple script to parse my downloads log?

         

shanelone7

8:12 pm on Apr 7, 2003 (gmt 0)

10+ Year Member



I run a small website that offers a few files for download, with bad luck a plenty...
anyways, the fact of the matter is that I need to limit my DAILY bandwidth to some degree, there are php scripts that can do that, but apparrent they don't work on gisol servers.

I've managed to record downloads to a log located at
/home/shane/logs/ with entries like this:

Tue Mar 18 04:39:55 2003*START:*/king/vol08.zip*0*5744257*67.124.5.1*67.124.5.1
Tue Mar 18 04:40:34 2003*DONE*/king/vol08.zip*0*5744257*67.124.5.1*67.124.5.1
Tue Mar 19 03:30:52
2003*START:*/king/vol09.zip*0*5984323*127.113.2.4*127.113.2.4
Tue Mar 19 03:41:37 2003*DONE*/king/vol09.zip*0*5984323*127.113.2.4*127.113.2.4

where the 5744257 and 5984323 are bytes

now I need a simple cron job script that can sum up the total number of bytes downloaded today

it should work like this, the cron command will call it once every three hours or so and if the total number of bytes (downloaded today; the DONE bytes) exceeds a certain limit, a .htaccess file will be modified to lock users out of the directory with the files

I assumed that it would be an easy perl parse script, but I've worked quite a while on it and I can't get a working script (I suck), can anyone help?

I'm very grateful to whomever that read this.

bcc1234

8:44 pm on Apr 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here is an outline. It should not be too hard to implement.

- Copy log file to a secondary location (to make sure it's not the active one and not being written at the same time)
- Create an array of integers (or a list)
- Create an index counter (if working with a fixed array)
- Open log file for reading
- Read the file line-by-line
-- Store the current line in a string varialbe
-- Check if this line (now stored in the variable) contains DONE
--- If yes, regex this variable to get the size string
--- Conver the string (with the size) to integer
--- Store the integer in the array at the index accourding to the counter
--- Update the counter
- Close log file
- Initialize an integer variable for total amount
- Iterate through the array from 0 to counter-1
- If your total is larger than supposed to be, remove read permissions for those files

DrDoc

8:56 pm on Apr 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



...modified to lock users out...

I think shanelone7 talks about locking certain users, but not all, out... depending on how much has been downloaded from that IP (or similar).

If so, bcc1234, I'm afraid your suggestion wouldn't quite work, since it would lock everyone out when a certain limit has been reached...

shanelone7, are the logfiles huge? If not, a check can easily be performed right before download...

shanelone7

4:03 am on Apr 8, 2003 (gmt 0)

10+ Year Member



locking out all users would be fine;
the logfiles can easily exceed 1mb in a one week period

thanks, bcc1234
but can someone provide me with some sample code?
especially the part on implementing a "lock"

bcc1234

9:04 am on Apr 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



`chmod 600 filename` will lock out everybody, but the owner of the file. So unless the file is owned by www or nobody (depending on your box setup) it won't be readable.