Error level reporting not working in this batch job...

Down below is a batch job that isn't reporting errors if a file is in use and cannot be copied over to the destination servers.  The err log file is never generated...  Can anyone determine the problem?

Thanks.


@ECHO OFF
CALL v:\windows\BATCH\windowsLogStart.CMD STARTED %0
ECHO **********************************************************************>>V:\windows\windowsJOBS\glove\logs\gloveProd.log
CLS



@ECHO OFF
echo Date: %date% Time: %time% >>V:\windows\windowsJOBS\glove\logs\gloveProd.log
echo. >> V:\windows\windowsJOBS\glove\logs\gloveProd.log

CLS

ECHO Checking if file exist.

if exist "T:\hockey\football\glove\Prod\glove.exe" goto Found

:NotFound

rem What to do when file is Not Found

echo. >> V:\windows\windowsJOBS\glove\logs\gloveProd.err
echo. >> V:\windows\windowsJOBS\glove\logs\gloveProd.err
echo Date: %date% >>V:\windows\windowsJOBS\glove\logs\gloveProd.err
echo Time: %time% >>V:\windows\windowsJOBS\glove\logs\gloveProd.err
echo File is unavailable >> V:\windows\windowsJOBS\glove\logs\gloveProd.err
goto :EOF

:Found

rem What to do when file is Found

:Next_Step
echo Source Server on T:\hockey\football\glove\Prod\glove.exe>> V:\windows\windowsJOBS\glove\logs\gloveProd.log
dir "T:\hockey\football\glove\Prod\glove.exe" |find "glove.exe">> V:\windows\windowsJOBS\glove\logs\gloveProd.log
CLS
for %%K in ( Server1 Server2 Server3 Server4 ) do CALL :routine %%K
goto :done

:routine
:: %1 comes from the call line, not the command line
set zserver=%1

ECHO.
ECHO PREPARING TO COPY FILES : %zserver%
@echo off
ping -n 10  \\127.0.0.1 >NUL

echo. >>V:\windows\windowsJOBS\glove\logs\gloveProd.log
echo Destination Server:%zserver% >> V:\windows\windowsJOBS\glove\logs\gloveProd.log
@echo on
xcopy "T:\hockey\football\glove\Prod\glove.exe" \\%zserver%\user01\windows\glove\prod\ /Y /Z /D
@echo off
dir \\%zserver%\user01\windows\glove\prod\glove.exe |find "glove.exe">> V:\windows\windowsJOBS\glove\logs\gloveProd.log
echo. >> V:\windows\windowsJOBS\glove\logs\gloveProd.log

if errorlevel 5 goto diskwrite
if errorlevel 4 goto lowmemory
if errorlevel 2 goto abort
if errorlevel 1 goto abort2
if errorlevel 0 goto done

:diskwrite
echo. >> V:\windows\windowsJOBS\glove\logs\gloveProd.err
echo. >> V:\windows\windowsJOBS\glove\logs\gloveProd.err
echo Date: %date% >>V:\windows\windowsJOBS\glove\logs\gloveProd.err
echo Time: %time% >>V:\windows\windowsJOBS\glove\logs\gloveProd.err
echo DiskWrite error occurred during copy to %zserver% >> V:\windows\windowsJOBS\glove\logs\gloveProd.err
goto exit

:lowmemory
echo. >> V:\windows\windowsJOBS\glove\logs\gloveProd.err
echo. >> V:\windows\windowsJOBS\glove\logs\gloveProd.err
echo Date: %date% >>V:\windows\windowsJOBS\glove\logs\gloveProd.err
echo Time: %time% >>V:\windows\windowsJOBS\glove\logs\gloveProd.err
echo Insufficient memory to copy files, invalid drive or command-line syntax while copying to %zserver% >> V:\windows\windowsJOBS\glove\logs\gloveProd.err
goto exit

:abort
echo. >> V:\windows\windowsJOBS\glove\logs\gloveProd.err
echo. >> V:\windows\windowsJOBS\glove\logs\gloveProd.err
echo Date: %date% >>V:\windows\windowsJOBS\glove\logs\gloveProd.err
echo Time: %time% >>V:\windows\windowsJOBS\glove\logs\gloveProd.err
echo CTRL+C pressed during copy to %zserver% >> V:\windows\windowsJOBS\glove\logs\gloveProd.err
goto exit

:abort2
echo. >> V:\windows\windowsJOBS\glove\logs\gloveProd.err
echo. >> V:\windows\windowsJOBS\glove\logs\gloveProd.err
echo Date: %date% >>V:\windows\windowsJOBS\glove\logs\gloveProd.err
echo Time: %time% >>V:\windows\windowsJOBS\glove\logs\gloveProd.err
echo Error during copy to %zserver% >> V:\windows\windowsJOBS\glove\logs\gloveProd.err
goto exit


:exit
goto :EOF


:done

for %%J in ( Server5 Server6 Server7 ) do CALL :copynext %%J
goto :Finished


:copynext
:: %1 comes from the call line, not the command line
set srvnme=%1

ECHO.
ECHO PREPARING TO COPY FILES: %srvnme%
@echo off
ping -n 10  \\127.0.0.1 >NUL

echo. >>V:\windows\windowsJOBS\glove\logs\gloveProd.log
echo Destination Server:%srvnme% >> V:\windows\windowsJOBS\glove\logs\gloveProd.log
@echo on
net use \\%srvnme%\Eback$ /user:cmi\%username%
xcopy "T:\hockey\football\glove\Prod\glove.exe" \\%srvnme%\Eback$\ZENAPPS\W2KAPPS\DMIAPPS\glove\prod\ /Z /D
@echo off
dir \\%srvnme%\Eback$\ZENAPPS\W2KAPPS\DMIAPPS\glove\prod\glove.exe |find "glove.exe">> V:\windows\windowsJOBS\glove\logs\gloveProd.log
V:\windows\windowsJOBS\glove\logs\gloveProd.log
echo. >> V:\windows\windowsJOBS\AVM\logs\AVMProd.log

if errorlevel 5 goto diskwrite
if errorlevel 4 goto lowmemory
if errorlevel 2 goto abort
if errorlevel 1 goto abort2
if errorlevel 0 goto done

:diskwrite
echo. >> V:\windows\windowsJOBS\glove\logs\gloveProd.err
echo. >> V:\windows\windowsJOBS\glove\logs\gloveProd.err
echo Date: %date% >>V:\windows\windowsJOBS\glove\logs\gloveProd.err
echo Time: %time% >>V:\windows\windowsJOBS\glove\logs\gloveProd.err
echo DiskWrite error occurred during copy to %zserver% >> V:\windows\windowsJOBS\glove\logs\gloveProd.err
goto exit

:lowmemory
echo. >> V:\windows\windowsJOBS\glove\logs\gloveProd.err
echo. >> V:\windows\windowsJOBS\glove\logs\gloveProd.err
echo Date: %date% >>V:\windows\windowsJOBS\glove\logs\gloveProd.err
echo Time: %time% >>V:\windows\windowsJOBS\glove\logs\gloveProd.err
echo Insufficient memory to copy files, invalid drive or command-line syntax while copying to %zserver% >> V:\windows\windowsJOBS\glove\logs\gloveProd.err
goto exit

:abort
echo. >> V:\windows\windowsJOBS\glove\logs\gloveProd.err
echo. >> V:\windows\windowsJOBS\glove\logs\gloveProd.err
echo Date: %date% >>V:\windows\windowsJOBS\glove\logs\gloveProd.err
echo Time: %time% >>V:\windows\windowsJOBS\glove\logs\gloveProd.err
echo CTRL+C pressed during copy to %zserver% >> V:\windows\windowsJOBS\glove\logs\gloveProd.err
goto exit

:abort2
echo. >> V:\windows\windowsJOBS\glove\logs\gloveProd.err
echo. >> V:\windows\windowsJOBS\glove\logs\gloveProd.err
echo Date: %date% >>V:\windows\windowsJOBS\glove\logs\gloveProd.err
echo Time: %time% >>V:\windows\windowsJOBS\glove\logs\gloveProd.err
echo Error during copy to %zserver% >> V:\windows\windowsJOBS\glove\logs\gloveProd.err
goto exit

:exit
goto :EOF


:Finished

echo. >> V:\windows\windowsJOBS\glove\logs\gloveProd.log
echo Completed Job >>V:\windows\windowsJOBS\glove\logs\gloveProd.log
ECHO **********************************************************************>>V:\windows\windowsJOBS\glove\logs\gloveProd.log
echo. >> V:\windows\windowsJOBS\glove\logs\gloveProd.log

CALL v:\windows\BATCH\windowsLogEnd.CMD FINISHED %0
EXIT
LVL 1
mystikal1000Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lee W, MVPTechnology and Business Process AdvisorCommented:
You have to understand how things work - there are TWO outputs, Standard Output (StdOut) and Standard Error (StdErr).  Standard output (successes, informational output) is typically written to StdOut (which is represented by a 1 and can be omitted when redirecting output as it is assumed).  ERRORS are reported to StdErr, represented by a 2.  So you could do this, for example:

echo info 1>> success.log 2>> failure.log

which will put all success/info messages to a file called success.log and all failures/error messages to failure.log.

OR you could do this:

echo info 1>> script.log 2>>&1

which would put ALL output from both standard error and standard out to the same file.

In short, append 2>>&1 to every line you want to record in the file.
Lee W, MVPTechnology and Business Process AdvisorCommented:
Also, it would be a bit easier to read if you put the log file into a variable - for example:

SET LogFile=V:\Windows\WindowsJOBS\glove\logs\gloveProd.err

Then replace the >>V:\Windows\WindowsJOBS\glove\logs\gloveProd.err
with
>>%logfile%
mystikal1000Author Commented:
So for example, I would do this?

echo. >> %logfile%
echo. >> %logfile%
echo Date: %date% >>%logfile%
echo Time: %time% >>%logfile%
echo DiskWrite error occurred during copy to %zserver% >> %logfile%
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Lee W, MVPTechnology and Business Process AdvisorCommented:
Kinda... you still need to take standard error if you want to get the errors - so it would look like this:

SET LogFile=V:\Windows\WindowsJOBS\glove\logs\gloveProd.err
echo. >> %logfile% 2>>&1
echo. >> %logfile% 2>>&1
echo Date: %date% >>%logfile% 2>>&1
echo Time: %time% >>%logfile% 2>>&1
echo DiskWrite error occurred during copy to %zserver% >> %logfile% 2>>&1
mystikal1000Author Commented:
Thanks I will try that...
WallsyCommented:
I think the issue is that your errorcheck for the xcopy results occur way after the xcopy. The errorlevel you're checking is probably for the dir or find command in the line above.

Could you try moving the errorlevel stuff up to the line underneath the xcopy?

HTH,

Wallsy
mystikal1000Author Commented:
Your right Wallsy, but where should I put the Dir and find command so it will output the same?
K_2KCommented:
forgive me if stepping on toes,  I think Wallsy is saying to put the errorlevel checking before anything else after what you want to check for errors.  If you want the code based on xcopy errorlevel it's like this:
++++++
xcopy "T:\hockey\football\glove\Prod\glove.exe" \\%zserver%\user01\windows\glove\prod\ /Y /Z /D
if errorlevel 5 goto diskwrite
if errorlevel 4 goto lowmemory
if errorlevel 2 goto abort
if errorlevel 1 goto abort2
if errorlevel 0 goto done
+++++

then if you want the dir when it's good,  put it under the label:
:done


ALSO: (separate item below)
K_2KCommented:
You cannot have any two labels the same.

The second goto diskwrite (or done or abort or whatever) will still pass control to the top, under the FIRST matching label in the batch script, it does not start searching at current line.  
You have two choices:
1) Use the top ones to work with all calls to them  (use same server variable at top and bottom, or pass it with CALL, and use %1 )
2) change all labels below to something else and also change all the gotos. I like to add a prefix to my subs so it's obvious where they belong.  at the bottom you're in copynext, so:
if errorlevel 5 goto copynextdiskwrite
if errorlevel 4 goto copynextlowmemory
if errorlevel 2 goto copynextabort
if errorlevel 1 goto copynextabort2
if errorlevel 0 goto copynextdone


If there's no significant difference between the top part and the other 3 servers,  is there a reason not to put all 4 servers in the FOR command and shrink the top part into the copynext routine altogether?  this kinda falls in the "if it ain't broke don't fix it" catagory, but if it were all the same and only typed once, then the labels wouldn't need to change to become unique.
 
Good Luck,
(\o/)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
WallsyCommented:
No toes stepped on at all K_2K!

I must have missed the reply, because I completely forgot about this question... Some of these sods at my work have decided I need to EARN my obscene rate!  ;)

Wallsy
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.