BAT file will not run from Task Scheduler but will from Command Line
Posted
by
wtaylor
on Server Fault
See other posts from Server Fault
or by wtaylor
Published on 2011-11-29T01:36:50Z
Indexed on
2011/11/29
1:52 UTC
Read the original article
Hit count: 828
windows-server-2008-r2
|task-scheduler
I'm trying to run a BAT script from Task Scheduler in Windows 2008 R2 and it runs for 3 seconds and then stops.
It says it successfully completes but I know it doesn't.
I can run this script from the command line directly, and it runs just fine.
The bat file I'm running actually deletes files older than 7 days using "forfiles" then I'm mapping a network drive, moving the files across the network using robocopy, and then closing the network connection.
I have taken the network and copy options out of the file and it still does the same thing. Here is how my file looks:
rem This will delete the files from BBLEARN_stats
forfiles -p "E:\BB_Maintenance_Data\DB_Backups\BBLEARN_stats" -m *.* -d -17 -c "cmd /c del @file"
rem This will delete the files from BBLEARN_cms_doc
forfiles -p "E:\BB_Maintenance_Data\DB_Backups\BBLEARN_cms_doc" -m *.* -d -14 -c "cmd /c del @path"
rem This will delete the files from BBLEARN_admin
forfiles -p "E:\BB_Maintenance_Data\DB_Backups\BBLEARN_admin" -m *.* -d -10 -c "cmd /c del @path"
rem This will delete the files from BBLEARN_cms
forfiles -p "E:\BB_Maintenance_Data\DB_Backups\BBLEARN_cms" -m *.* -d -10 -c "cmd /c del @path"
rem This will delete the files from attendance_bb
forfiles -p "E:\BB_Maintenance_Data\DB_Backups\attendance_bb" -m *.* -d -10 -c "cmd /c del @path"
rem This will delete the files from BBLearn
forfiles -p "E:\BB_Maintenance_Data\DB_Backups\BBLEARN" -m *.* -d -18 -c "cmd /c del @path"
rem This will delete the files from Logs
forfiles -p "E:\BB_Maintenance_Data\logs" -m *.* -d -10 -c "cmd /c del @path"
NET USE Z: \\10.20.102.225\coursebackups\BB_DB_Backups /user:cie oly2008
ROBOCOPY E:\BB_Maintenance_Data Z: /e /XO /FFT /PURGE /NP /LOG:BB_DB_Backups.txt
openfiles /disconnect /id *
NET USE Z: /delete /y
This is happening on 2 servers when trying to run commands from inside a BAT file.
The other server is giving an error if (0xFFFFFFFF) but that file is running a CALL C:\dir\dir\file.bat -options
and I've used commands like that before in Server 2003.
Here is the file for this file:
call C:\blackboard\apps\content-exchange\bin\batch_ImportExport.bat -f backup_batch_file.txt -l 1 -t archive
NET USE Z: \\10.20.102.225\coursebackups\BB_Course_Backups /user:cie oly2008
ROBOCOPY E:\ Z: /move /e /LOG+:BB_Move_Course_Backups.txt
openfiles /disconnect /id *
NET USE Z: /delete /y
Any help would be GREAT. Thanks
© Server Fault or respective owner