Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

User Current Date in batch file command

Posted on 2003-11-21
4
Medium Priority
?
1,003 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 900 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction How to create multiboot configuration with XP\Vista and Windows 7 on it? And most important question - how to do this correctly so not to have any kind of nightmares we get when system gets screwed? First of all one should realize t…
Windows 10 is here and for most admins this means frustration and challenges getting that first working Windows 10 image. As in my previous sysprep articles, I've put together a simple help guide to get you through this process. The aim is to achiev…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

610 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