Take the 2-minute tour ×

I have a BAT/CMD file that when run from the command prompt runs completely. When I run it through the Task Scheduler it partially runs.

Here is a copy of the file

ren Apps_Backup*.* Apps.Bak
ren Apps_Was_Backup*.* Apps_Was.Bak
xcopy /Y c:\sqlbackup\*.bak c:\sqlbackup\11\*.bak
xcopy /y c:\sqlbackup\*.bak \\igweb01\c$\sqlbackup\*.bak
Move /y c:\sqlbackup\*.bak "\\igsrv01\d$\sql backup\"

The last two lines do not run when the task scheduler calls it. But again, work when manually run from the command line.

All the local sever commands run but when it comes to the last two lines where it goes to another server then it does not work.

share|improve this question
add comment

3 Answers

Looks like your scheduled task user account doesn't have rights to write to \\igweb01\c$\sqlbackup and \\igsrv01\d$\sql backup.

share|improve this answer
To amplify - if you're running as the system account, change it to a different or new account that only has the rights needed to perform the tasks. Often called a "service account" because no one should be logging in with that account, only used for automated processes. –  mfinni Feb 18 '10 at 17:28
add comment

Currently Administrator is the account I am using. Same user name and password on all three severs. I thought by using administrator for the task would alleviate that issue.

I just tested using a 3rd party scheduler and it worked perfectly. not sure what is up with Task Scheduler

share|improve this answer
add comment

2 remarks:

I. in a winxp vm I have handy, the syntax for xcopy is xcopy source dest /switches, not xcopy /switches source dest as you have there.

II. move.exe in this vm wants to have a drive letter instead of a unc path. Try mapping the share to a drive letter and moving the files to the drive letter instead of to the unc path;

2 suggestions:

I. check the scheduled task log file (when you go to scheduled tasks, it's in the tools menu, I think), who knows, it may even tell what went wrong;

II. when scripting, always check the return levels of your actions. If batch scripting does not support this, use another scripting language (I would do this in Perl, I understand most windows admins that script use Powershell these days).

Short of using a proper scripting language, at least write a log file of what has happened redirecting standard output and error to it. That way you can always see when something has happened what has happened.

share|improve this answer
add comment

Your Answer

