(Note that I will not changing jobs this week, so I will not be 
available at this e-mail address to answer questions about this 
directly. I'm not sure when I will get a chance to resubscribe to the 
list).

A few months ago, I mentioned that it's easy to set up Analog to analyse 
daily IIS logs on NT by using the following FOR command to get today's 
date:

  FOR /F "tokens=2,3 delims=/ " %%f in ('date /t') do set today=%%f%%g 
  ANALOG y:\folder\ex00%today%.log

(This is for US date formats - mm/dd/yyyy. Use today=%%g%%f for 
dd/mm/yyyy locales. The FOR command takes the output of the 'date /t' 
command and breaks it into separate chunks, using / and the space 
character as delimiters. I only care about the 2nd and 3rd chunk, which 
will be assigned to variables starting with %f, so %f gets the first 
chunk, and %g gets the second, etc).

I pointed out that this really only works for people west of GMT, 
because the logs roll over at 00:00 GMT, so that people in the EST time 
zone can operate on "yesterdays" log file today.

Mark Hoy from the UK prompted me to look at this again. He asked if 
there was a way to schedule analog to process monthly logs. When I first 
looked at this, I tried the /A switch for the SET command that allows 
you to do basic arithmetic, eg SET /A LASTMONTH=MONTH-1 but I ran into a 
problem when I got to August and September, because the SET command 
treats numbers starting with 0 as Octal, so 08 and 09 aren't valid 
numbers. But I found that I could add 100 to the number, subtract one, 
and then do a string operation to extract the last two characters:

  FOR /f "tokens=2 delims=/ " %%f IN ('date /t') DO SET month=%%f 
  SET /A lm=1%month%-1
  SET lastmonth=%lm:~1,2%
  ANALOG y:\folder\ex00%lastmonth%.log

(The ":~1,2" pulls the 2 characters starting after the first character. 
So if month=09, lm=109-1=108 and lastmonth is the second and third 
character in lm, ie 08).

Obviously, this doesn't work in January, because it doesn't return 12 
for last month. But you can extend the script just slightly to deal with 
this:

  FOR /f "tokens=2" %%f IN ('date /t') DO SET today=%%f 
  SET year=%today:~8,2%
  SET /A lm=1%today:~0,2%-1
  SET lastmonth=%lm:~1,2%
  IF %lastmonth% NEQ 00 GOTO finish
  SET lastmonth=12
  SET /A lastyear=1%year%-1
  SET year=%lastyear:~1,2%
  :finish
  ANALOG y:\folder\ex%year%%lastmonth%.log

(today gets the full date string 09/25/2000. Year is the 9th and 19th 
character (00). lm=109-1, lastmonth=08. If lastmonth=00, set 
lastmonth=12 and decrement the year).

If DATE /T returns day/month/year, then the third line needs to modified 
slightly: SET /A lastmonth=1%today:~3,2%-1  

Aengus

------------------------------------------------------------------------
This is the analog-help mailing list. To unsubscribe from this
mailing list, send mail to [EMAIL PROTECTED]
with "unsubscribe" in the main BODY OF THE MESSAGE.
List archived at http://www.mail-archive.com/analog-help@lists.isite.net/
------------------------------------------------------------------------

Reply via email to