mardi 13 juin 2017

cannot call subroutine in batch file when launched from Task Scheduler

I have written a simple batch file script that is used to back up test data daily, weekly and monthly.

The script works well if i run the batch file directly, however I have encountered a problem when launching from Windows Task Scheduler (Windows 10).

I have a log file that the batch file writes to, so I know that the script executes. However the problem appears to be when using if statements and calling subroutines.

the main piece of code looks like this:

:: call daily backup every day    
call :dailybackup

:: call weekly backup if today is sunday
if %day%==Sun ( call :weeklybackup )

:: call monthly backup if today is the 28th
if %dd%==28 ( call :monthlybackup )

call :log "FINISHED"

:: main program complete - exit batch file
exit /b

The each sub routine writes log messages to the log file. I have verified that the :weeklybackup and :monthly backup routines are called correctly when I run the batch file manually, however not when run from Task Scheduler. The :dailybackup routine executes always.

Just one point to clarify, I know that the batch file exits cleanly as I receive the "FINISHED" log message.

Any thoughts are greatly received

Aucun commentaire:

Enregistrer un commentaire