Link to home
Start Free TrialLog in
Avatar of davidpm
davidpmFlag for United States of America

asked on

batch file logging

The following is a batch file that I am using for an auxilery backup

xcopy \\dc1\data\*.* d:\public\data /s /d /c /y /i
xcopy \\dc1\doc\*.* d:\public\doc /s /d /c /y /i
xcopy \\dc1\archive\*.* d:\public\archive /s /d /c /y /i
xcopy \\server2b\public2\*.* d:\public\public2 /s /d /c /y /i

What I would like to have happen is that in the d:\public directory
I get a file created every day that looks like this: 2003-04-05 Sat.txt
And in that file are lines something like
\\dc1\data OK
\\dc1\doc Failed
\\dc1\archive OK
\\server2b OK

I know I using the continue on error xcopy switch so the error code will probably return OK even if some files did not copy.
At least I would know that each line executed and that would be good enough.

Anyone have some batch file code that would do this?





Avatar of Nick67
Nick67
Flag of Canada image

atBatch files execute in order.  Since you have xcopy set to carry on despite errors, I am not sure you can get any meaningful pass/fail data.  You can structure things so that you can tell if each command executed though.  I don't have the exact code with me anymore, I set up a similar system for a client 18 months ago, though.  Create a separate batch file for each line of code you have above.  Create a batch file that calls each one of those new batch files.  In each of the new batch files follow your xcopy line with

date < yes.txt >test.txt

What this does is output the contents of the date command to test.txt.  Yes.txt needs to contain the commands necessary to get the date command to complete--a single enter key, usually.  Piping in yes.txt to the date command automates the completion of the command.  By placing the date command after the xcopy command, the only way it can be executed is if the xcopy command completes. Test.txt will then contain a date entry for each time your batch file runs.

Hope this helps.

Nick
ASKER CERTIFIED SOLUTION
Avatar of billious
billious

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you would like to get a easy report in text form, try using the "RoboCopy.exe" from the Windows 2000 Resource Kit.  Using this in a batch file along with piping the results to a text document should give you a nice report.  It is a nice alternative to "Xcopy".

Hope this helps,

Mirfster.
Avatar of davidpm

ASKER

My final solution used part from you and mirfster. Attached is what I plan on using. It seems to work great.
Where you came up with the syntax for the set filename I would be intersted in if you have a resource.

Mirfster I knew about robocopy and xxcopy but forgot about the reporting facility.
I have created an new question for you. Just log in to the question "batch file logging for mirfster" and collect your points.

set filename=%date:~10,4%-%date:~4,2%-%date:~7,2% %date:~0,3%.txt
robocopy \\dc1\doc\david d:\test\david /s /np /eta /log:"%filename%"
robocopy \\dc1\doc\bob d:\test\bob /s /np /eta /log+:"%filename%"
Avatar of billious
billious

davidpm:

set/? from the command prompt.

AAMOI, there's a potential problem with the date/t or %date% syntax on XP caused by some Microsoft brainstorming. Very messy - just in case you choose the "wrong" options should you upgrade.

<hobbyhorse>
For more discussion:
https://www.experts-exchange.com/questions/20571603/DATE-T-OS-When-is-XP-not-XP.html

or
https://www.experts-exchange.com/questions/20577896/Copy-files-2-day-before-current-date.html

</hobbyhorse>

Thanks for the points davidpm, I'll make sure to go to that question.

Best off luck.

Mirfster