Solved

User Current Date in batch file command

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Syslinux UEFI USB boot 4 369
Ubuntu 16.04 Emergency Boot 2 170
Administrator Tools 2 70
Pop up error related to internet explorer 5 58
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
#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.

863 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

24 Experts available now in Live!

Get 1:1 Help Now