Link to home
Start Free TrialLog in
Avatar of flaggkort
flaggkort

asked on

DOS batch file to copy and generate a log file only if there's an error

I have a batch file I've written that copys a file every night over our VPN from each of our stores to the server.  The problem is that if there's an error then I don't know it.  Is there a way using a switch or DOS to generate a log.txt file only if there's an error such as if the VPN were down?  Below is an example of my file at present.

copy "\\192.168.2.121\Title Loan Professional Plus\database\titleloan2k_be.mdb" N:\Athens /y /z
ASKER CERTIFIED SOLUTION
Avatar of t0t0
t0t0
Flag of United Kingdom of Great Britain and Northern Ireland image

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
I meant %date% in the above code - not %dat% (a typo)

This might look neater:

copy /y /z "\\192.168.2.121\Title Loan Professional Plus\database\titleloan2k_be.mdb" N:\Athens 2>>error.log
if not %errorlevel% equ 0 (
   echo %date% %time% Error occured copying titleloan2k_be.mdb >>error.log
)

Avatar of flaggkort
flaggkort

ASKER

For some reason the second answer didn't work but this one worked perfectly.  Thanks!