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
Solved

User Current Date in batch file command

Posted on 2003-11-21
4
999 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Many people tend to confuse the function of a virus with the one of adware, this misunderstanding of the basic of what each software is and how it operates causes users and organizations to take the wrong security measures that would protect them ag…
#Citrix #POC #XenDesktop #vCenter #VMware #ESX
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.

809 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