Pjb0222
1095 pts. | Jun 8 2009 3:28PM GMT
Robocopy has a logging switch that includes the command options, list of files copied, status of the copy of each file, start and stop time of the copy session and a summary of the copy results. You can massage the file name of the log as desired.
Can you give an example of your copy and what a log filename should look like?
Adding the date time into a file name is covered by alot of people, here is one example:
Pjb0222
1095 pts. | Jun 8 2009 3:29PM GMT
So, using the link button didn’t work.
<a href="http://blogs.msdn.com/bill/archive/2009/02/13/file.aspx" title="http://blogs.msdn.com/bill/archive/2009/02/13/file.aspx" target="_blank">http://blogs.msdn.com/bill/archive/2009/…</a>
MicJ
155 pts. | Jun 9 2009 8:04PM GMT
What I am trying to get to is a line for each item copied/moved broken down as follows:
Date_Time(copied/moved)_filename_DestinationDirectory
My current syntax is
Robocopy:
C:Utilitiesrobocopy C:TEMPPageSorting C:TEMPPagesSent na*.pdf /R:3 /W:3 /MOV /NP /NS /IS /FP /NDL /NJH /NJS >>TodaysPages.log
XCopy
date /T >>C:TEMPTodaysPages.log
time /T >>C:TEMPTodaysPages.log
xcopy C:TEMPna*.pdf C:TEMPPagesSent /C /Y >>TodaysPages.log
Pjb0222
1095 pts. | Jun 9 2009 10:05PM GMT
My suggestion is to use Robocopy’s built in logging and to leave the job header and job summary enabled. While there is more information in these items, they also have the information necessary to perform basic troubleshooting should an issue occur. The job header includes start date and time and the job summary includes completion date and time. Using the log append allows you to keep prior information. Or you can roll the log in your script as you require.
C:\Utilities\robocopy C:\TEMP\PageSorting C:\TEMP\PagesSent na*.pdf /R:3 /W:3 /MOV /NP /NS /IS /FP /NDL /LOG+:C:\Temp\TodaysPages.log
Once you have the log, you can strip information out as required with a for loop and the various string utilities (findstr, find, grep). Example:
FOR /F “tokens=3″ %a IN (’findstr /i /r “[a-zA-Z0-9].cmd” C:\Temp\TodaysPages.log’) DO @ECHO %a>>C:\Temp\_MySrt.lst
You can also strip out date and time stamps using a for loop and filter them into your results.
You can also use the build in DATE and TIME variables to manually flag you log file.
MicJ
155 pts. | Jun 10 2009 2:36PM GMT
Thanks for this info. I would like to eliminate the need for post-parsing of the log file as it may be used for troublshooting in real time. The current batch file is running as a Windows service, running 7 X 24 with many files being moved during our production hours each day. I am looking for a way to make this as clean and as lean as possible at the creation of the log entries appended to the log file throughout the day. Perhaps taking this a step back to simplify things might help me.
Is there a way to do a simple command to copy a file (using any tool/app) that will create a simple entry in a log file to have a single line item for that file stating Date, Time, Filename, destination directory. If we can write the log file cleanly, there should be little to no post parsing of the log file needed.
Labnuke99
26360 pts. | Jun 10 2009 3:36PM GMT
Here’s a script file I have in my library. Maybe this will do the job for you.
@echo off ::LogEntryDemo.bat REM Jeffery Hicks <a href="mailto:jhicks@sapien.com" title="mailto:jhicks@sapien.com">jhicks at sapien.com</a> REM This script doesn’t really do much other than demonstrate REM how to use the LogEntry routine to create a REM log file with a timestamped entry for each line. REM define path to log file set myLog=e:templog.txt REM Delete the logfile if it already exists. if exist %myLog% del %myLog% >NUL Echo Working… REM When sending something to the log routine, enclose the REM message in quotes. Call :LogEntry “Starting %0″ Call :LogEntry “Running DIR” DIR %windir%*.* /s >NUL Call :LogEntry “Finished DIR” Call :LogEntry “Sleeping for 30 seconds” Sleep 30 Call :logEntry “Getting NETSTAT information” REM Sending results of a NETSTAT command to the log. Notice REM I’m enclosing the output in quotes. Otherwise, only the REM first part of the output would be recorded. for /f “tokens=*” %%t in (’netstat ^|find /i “TCP”‘) do @Call :LogEntry “%%t” Call :LogEntry “Finishing logging and opening %myLog%” REM Display the log start Notepad %MyLog% GOTO :EOF :LogEntry REM Output will be like: Wed 11/15/2006 05:27 PM “Starting LogEntryDemo.bat” for /f “tokens=*” %%i in (’date /t’) do @for /f “tokens=*” %%j in (’time /t’) do @echo %%i%%j %1 >>%myLog% GOTO :EOF :EOF
This works well to timestamp log entries.
In the IT trenches? So am I - read my IT-Trenches blog
MicJ
155 pts. | Jun 11 2009 3:45PM GMT
Thanks for this thorough script. It helps but of course, as a basic scripter I have questions.
In trying to run this on my test workstation - WinXP, I ran your script as is. It did not work so I attempted to run this line by line. When running the line “Call :LogEntry “Starting %0″” from the Windows command line, the following error message appeared: “Invalid attempt to call batch label outside of batch script”
Have I missed something with this?
Troy Tate
0 pts. | Jun 25 2009 4:43PM GMT
You cannot run individual lines outside the script since there is not any context for some of the calls made in the script. You cannot just cut/paste from the window here due to some issues with this wiki. Unfortunately, you will need to retype the script exactly as shown.






