Link to home
Start Free TrialLog in
Avatar of jamesd84
jamesd84Flag for Australia

asked on

Scheduled task in Windows server 2003 returns 0x2 and doesn't seem to run batch file

I am running 2 scheduled tasks on a Windows 2003 server. Each of these calls a separate batch file to run various backup and database maintenance processes on a  Mimer SQL database. These have both been working correctly for months. In the last 3 days they have stopped working.

When I run the batch files manually (in explorer) they complete everything correctly. When they are set to run as scheduled they do not complete the tasks and return last result 0x2.

I have looked up this code and believe it to mean: ERROR_FILE_NOT_FOUND 2 The system cannot find the file specified. From http://msdn2.microsoft.com/en-us/library/ms681382.aspx 

Ive checked the paths and all looks OK. What can this mean?


 
Avatar of SteveGTR
SteveGTR
Flag of United States of America image

If you are using mapped drives they might not be available. I'd suggest using URNs:

\\server\share\dir
Avatar of jamesd84

ASKER

Thanks for your response, both batch files are local to the server.
ASKER CERTIFIED SOLUTION
Avatar of JohnGerhardt
JohnGerhardt
Flag of Switzerland 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
Can you post 1 of the batch files?
I have re-created both tasks - thanks for that suggestion John. Ive just got a funny feeling that it is scheduled tasks bug, because after I re-created the tasks and ran them, the scripts ran and the backup was successful - but it still exited with 0x2. Thoughts?

Here is one of the batch files

**START

CD\OASIS824CM
 
REM - Delete all dbc and log files in the backup folder
DEL C:\OASIS824CM\backup\*.dbc
DEL C:\OASIS824CM\backup\*.log
 
REM - Set database offline/online to clear cache
BSQL OASIS824CM <OFFLINE.TXT
BSQL OASIS824CM <ONLINE.TXT
 
REM - Stop Mimer Database
NET STOP MIMER-OASIS824CM
MIMCONTROL -t OASIS824CM
 
REM - Perform  physical checks on system databank
DBC C:\OASIS824CM\data\sysdb92.DBF C:\OASIS824CM\backup\sysdb92.DBC
REM - Restart Mimer Database
NET START MIMER-OASIS824CM
MIMCONTROL -s OASIS824CM
 
REM - Force Database Online Again in case of errors
BSQL OASIS824CM <ONLINE.TXT
 
REM - Call Utils to verify database
xcopy C:\OASIS824CM\oasis8.ini C:\oasis8\oasis8.ini /y /e /h /c
C:\OASIS824CM\UTILS82E [VERIFY]
 
REM - If Utils writes a flag file then drop out
If exist C:\OASIS824CM\backup\DBC.LOG goto :EOF
 
REM - Delete all dbf files in backup directory
DEL C:\OASIS824CM\backup\*.dbf
 
REM - Stop Mimer Database and Dos Copy Files
NET STOP MIMER-OASIS824CM
MIMCONTROL -t OASIS824CM
XCOPY C:\OASIS824CM\log\*.DBF C:\OASIS824CM\logarch1 /y /e /h /c /i
COPY C:\OASIS824CM\data\*.DBF C:\OASIS824CM\log
 
REM - Restart Mimer Database
NET START MIMER-OASIS824CM
MIMCONTROL -s OASIS824CM
 
REM - Perform an online backup
BSQL OASIS824CM <OBACKUP.TXT
 
 
REM - Force Database Online Again in case of errors
BSQL OASIS824CM <ONLINE.TXT

**END
One thing you might do is alter your initial cd command to this:

CD /D C:\OASIS824CM

Other than that it looks good to me. The only thing I can think is that the last BSQL command is returning the code. You could dump some debugging information:

BSQL OASIS824CM <ONLINE.TXT
(echo [%date% %time%] Errorlevel: %errorlevel%)>>debug.txt

Avatar of r-k
r-k

Anything of interest in the Scheduler log?
(Scheduled Tasks -> Advanced -> View Log)
Thanks everyone for your input - im kicking myself. After re-creating the tasks it is working again. Lots of other scheduled tasks were created by another tech - maybe this had something to do with it. Does scheduler have a bug of this nature??
Thanks a heap John - sometimes the simplest thing hey ;)
I was receiving the same 0x2 error message when trying to execute a batch script that used mapped network drives. Once I removed mapped network drives, and specified the full patch \\machine\folder, ie... it works.