logfiles and date math
logfiles and date math
- Subject: logfiles and date math
- From: dean ross-smith <email@hidden>
- Date: Thu, 8 May 2003 09:13:11 -0700
hi all-
I'm working on a logfile problem in os 9.2.2. I'm trying to truncate
logfiles for an FTP script that uses Fetch. I've found 3 ways to
truncate logs: brute force truncate to X number of lines, rotate the
logs so that I have daily logs.1 through logs.7 or I can read in the
logfile and keep X days worth of files.
I thought option 3 would be the most elegant and coded it. My problem
is that it is pretty slow. I'm wondering if anyone has ideas how to
speed up the date parsing in the repeat loop.
The log format is like this...
May 6, 2003 7:57 PM
----] Stopping SpeedRJ
May 6, 2003 8:47 PM
----] Starting SpeedRJ
May 6, 2003 8:52 PM
----] Sent Asura_Hot_Folders:classified:classpag_bw_out:cd2749095
----] 172.16.140.53/
May 6, 2003 8:52 PM
----] Sent Asura_Hot_Folders:classified:classpag_bw_out:cd2749095
----] 172.16.140.54/
-- try statements removed to save a few lines
on logfiletruncate(myfile, numdays)
set CR to (ASCII character of 13)
set od to text item delimiters
set text item delimiters to CR
set founddate to false
set tempfounddate to false
set myfileref to (open for access file myfile with write permission)
set linelist to (read myfileref as {text} using delimiter {CR}) as list
set linecounter to 1
set lastline to 1
set mycurdate to (current date) as date
repeat until ((linecounter > (count of linelist)) or (founddate =
true))
if not (item linecounter of linelist starts with "----]") then
set mydate to date (item linecounter of linelist)
if (((mycurdate - mydate) as number) / days) > numdays then
set tempfounddate to true
set lastline to linecounter
else
if tempfounddate = true then
set founddate to true
set lastline to linecounter
end if
end if
end if
end repeat
-- if we found an old date but not one within numdays from the current
date, then tempfounddate will be true.
if ((founddate = true) or (tempfounddate = true)) then
set newlist to (items lastline thru (count of linelist) of linelist)
as list
set eof myfileref to 0
write (every text item of newlist as text) to myfileref
close access myfileref
-- write an entry to the log saying what we did
my logfile(myfile, {"truncated log to " & (numdays * -1 as text) & "
days out."})
end if
set text item delimiters to od
try
close access myfileref
end try
return
end logfiletruncate
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.