Solved

User Current Date in batch file command

Posted on 2003-11-21
4
986 Views
Last Modified: 2008-01-16
I need to manipulate my server log file where the file name is in the format:
ex031121.log or 'ex'+year+month+day+'.log'.

So if I need to execute:
[a bunch of stuff]
copy C:\WINDOWS\system32\LogFiles\W3SVC1\ex031121.log c:\holder
[a bunch more stuff]


how would I generalize that so I don't have to edit the batch each day.
0
Comment
Question by:juststeve
  • 2
4 Comments
 
LVL 57

Expert Comment

by:Pete Long
ID: 9797362
Hi juststeve,
@echo off
set filename=%date:~10,4%-%date:~4,2%-%date:~7,2% %date:~0,3%.txt
xcopy \\dc1\data\*.* d:\public\data /s /d /c /y /i
call :report %errorlevel% \\dc1\data
xcopy \\dc1\doc\*.* d:\public\doc /s /d /c /y /i
call :report %errorlevel% \\dc1\doc
xcopy \\dc1\archive\*.* d:\public\archive /s /d /c /y /i
call :report %errorlevel% \\dc1\archive
xcopy \\server2b\public2\*.* d:\public\public2 /s /d /c /y /i
call :report %errorlevel% \\server2b\public2
set filename=
goto :eof

:report
if %1==0 set status=OK
if not %1==0 set status=Failed
echo %2 %status% at %time%>>"%filename%"
set status=
goto :eof



Should do what you want, provided xcopy complies with the claimed 'errorlevel 0 if it works' behaviour.

...Bill
From http://oldlook.experts-exchange.com/Operating_Systems/Win2000/Q_20575727.html?query=batch+date+filename&searchType=topic

Cheers!
0
 

Author Comment

by:juststeve
ID: 9797453
Thankx Bill...my fault for phrasing the question specific to the COPY command. Actaully this is the line than needs to be generalized:

"c:\program files\log parser\preplog" C:\WINDOWS\system32\LogFiles\W3SVC174669028\ex031121.log > C:\WINDOWS\system32\LogFiles\W3SVC174669028\out.txt
0
 
LVL 1

Accepted Solution

by:
Archie_Gremlin earned 300 total points
ID: 9799046
In that case you want something like this:-

set filename=ex%DATE:~12,2%%DATE:~7,2%%DATE:~4,2%.log
"c:\program files\log parser\preplog" C:\WINDOWS\system32\LogFiles\W3SVC174669028\%filename% > C:\WINDOWS\system32\LogFiles\W3SVC174669028\out.txt

regards,
Gremlin
0
 

Author Comment

by:juststeve
ID: 9802563
Thankx Archie....a minor adjustment for sake of the archives... to get the month and day in the correct order the code should read:

set filename=ex%DATE:~12,2%%DATE:~4,2%%DATE:~7,2%.log
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Occasionally Windows/Microsoft Updates will fail to update. We have found a code that will delete all temporary files and re-register all dll's related to Windows/Microsoft Updates! This works 99% of the time to get the updates working again! The…
As the title indicates, I have done this before. It chills me everytime I update the OS on my phone, (http://www.experts-exchange.com/articles/18084/Upgrading-to-Android-5-0-Lollipop.html) because one time I did this and I essentially had a bricked …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now