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