1. Loop through every available log file in a given directory:
FOR /f "delims=" %%F IN ('dir \\server\path\*.log /b') DO (
LogParser "SELECT date, time, c-ip, cs-username, s-computername, s-ip,
s-port, cs-method, cs-uri-stem, sc-status, sc-win32-status, sc-bytes,
cs-bytes, time-taken INTO \\server\%%F FROM \\server\path\%%F WHERE
(generic constraint)" -i:IISW3C -o:CSV -headers:ON -filemode:0
-e:1000000000
)
Log parser is run on every log file found in the source directory and
copies the output to another server. The problem is that when I re-run
this to get the next day's log files, log parser appends log data to
the already existing log files. Is there a way to have this thing
exclude any log files that already exist in the output destination
directory?
I realize this is probably an easy answer, but I'm getting mind numb
and would appreciate any suggestions.
Thanks,
C.
If I understand what is input and what is output, then try something
like this:
FOR /f "delims=" %%F IN ('dir \\server\path\*.log /b') DO (
IF NOT EXIST \\server\%%F LogParser + rest of command line
)
Assumes that \\server\%%F is what you mean by a log file that
already exists.
--
William Allen
Free interactive Batch Course http://www.allenware.com/icsw/icswidx.htm
Batch Reference with examples http://www.allenware.com/icsw/icswref.htm
Header email is rarely checked. Contact us at http://www.allenware.com/
Solution 1: rename each processed file to ...log.parsed
Solution 2: (but this might conflict with backup procedures)
FOR /f "tokens=1*" %%I IN ('attrib \\server\path\*.log') DO if %%I==A
attrib -a %%J&{then your logparser line - noting that %%J is your
fully-qualified filename}
(preferably put the "attrib -a %%J" after your logparser command to make
sure the "A" attribute is only reset AFTER it has been "logparsed"
Solution 2a: along the same lines, but play with the "hidden" or "read-only"
flags - even the "System" flag...
Solution 3: echo the filenames to a history file as they are processed, and
then findstr /b /e "filename" in the history file, logparsing if not-found
(errorlevel >0)
HTH
...Bill