1.

Solve : Current Date -1?

Answer»

Hi

I need some help creating a batch file which basically takes the NAME of a file (which is made up of the date) and then the date being reduced by one. For example:

I import IIS Weblogs on a daily basis, however I always TAKE yesterdays file. Therefore this morning I imported the file labelled ex080102.log. What I would like to do is using a variable which takes the current date, get the batch file to retrieve the day befores log file.

The code I have so far is as follows:

@ECHO OFF
REM **********************************************
REM ** Batch file to open location of Weblogs on Web Server 1
REM ** and Web Server 2 and then copy to E:\weblogs
REM **********************************************

:BEGIN
CLS

REM ** Set the variables

SET WS1=Web Server 1
SET WS2=Web Server 2
SET CurrDate=%date:~-2,2%/%date:~-7,2%/%date:~0,2%

REM ** Create mapped drives on both web servers

net use P: \logs\W3SVC1597409361 /persistent:no
ECHO %WS1% weblogs directory mapped successfully to P:\
ECHO.
net use Q: \Logs\W3SVC1597409361 /persistent:no
ECHO %WS2% weblogs directory mapped successfully to Q:\

REM ** Give the USER 4 options to choose from

ECHO.
ECHO 1
set choice=
set /p choice=Select the number of weblogs you wish to copy from the web servers:
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='1' goto One
ECHO "%choice%" is not valid please try again
ECHO.
goto start
:One



goto end
:END

What I need is the code that is executed when the user selects option 1 to copy 1 days worth of logs back from the servers. Once I have this I can then update the code to have 2 or more days worth etc.

Thanks in advance.Microsoft have a very useful utility program, Logparser - FREELY downloadable from here http://www.iis.net/downloads/default.aspx?tabid=34&i=1287&g=6

I use it to put the date into variable %yesterday% like this :

Code: [Select]"C:\Program Files\Log Parser 2.2\logparser.exe" -o:NAT -q:on "Select Top 1 TO_STRING(SUB(SYSTEM_TIMESTAMP(), TIMESTAMP('01-02', 'MM-dd')), 'yyMMdd') as d1 Into '\yesterday.txt' From System"
Set /P Yesterday=<\Yesterday.Txt
Del \Yesterday.Txt
Or you could search for a vbscript solution

Graham
Thanks Graham

That worked perfectly.



Discussion

No Comment Found