We help IT Professionals succeed at work.

Batch File - Delete Command Failing when run from Task Scheduler

1,056 Views
Last Modified: 2012-05-11
Hi

I have a batch file (text below) that fully works as expected when manually executed, but when executed by the Task Scheduler the Delete command fails - where the Copy and Rename commands within the batch both work correctly. It's just the Delete command that fails.

NOTE:
The copy and rename commands work, the Deleted doesn't

Everything works when run manually
I have tried adding 'ECHO Y | ' before the Del command - no joy
I have tried adding ' /Q' after the Del command - no joy
The E:\ drive is an actual drive on the server - not a mapped drive
I am running Windows Server 2008 R2

-=-=-=-=-=-=-=-=-=-=-=-=-
@ECHO OFF
E:
cd Mm_BAKs
CLS
ECHO ***********************************************
ECHO This deletes the old files
ECHO ***********************************************
ECHO.
ECHO Deleting old bak files
Del E:\Mm_BAKs\*.bak
ECHO.
ECHO ***********************************************
ECHO This imports the latest Live backup
ECHO ***********************************************
ECHO.
ECHO Copying L_Live file - this may take a while!
Copy "\\SOME-SERVER\DB Backup Folder\L_backup*.bak" E:\M_BAKs
ECHO.
ECHO Renaming L_backup file to L_Live_backup.bak
REN E:\Mm_BAKs\L_backup*.bak L_Live_backup.bak
Echo.
Echo.
ECHO **********************************************
ECHO This imports the latest FS backup
ECHO **********************************************
ECHO.
ECHO Copying new FS file
Copy "\\SOME-SERVER\DB Backup Folder\FS_backup*.bak" E:\M_BAKs
ECHO.
ECHO Renaming FS file to FS_backup.bak
REN E:\Mm_BAKs\FS_backup*.bak FS_backup.bak
-=-=-=-=-=-=-=-=-=-=-=-=-=-

Any help really appreciated.

LoveToSpod
Comment
Watch Question

Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
IT Consultancy
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Steve KnightIT Consultancy
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Hi, thanks for the quick response!

If I execute the file manually it will be using my permissions. The scheduler runs from a domain account which belongs to the Administrators group on the Server - therefore [I would have thought] has the permission to delete.
The two directories is a typo from sanitising!
Just trying out the logfile to check the output.

Author

Commented:
I have enabled full-control permissions for the account that runs the scheduled task on the source copy folder (where the original files are) and the destination copy folder. When I run it now from the scheduler IT WORKS!! . Permissions it is!!

Thanks for your help,

LoveToSpod


Author

Commented:
Top notch, thanks!
Steve KnightIT Consultancy
CERTIFIED EXPERT

Commented:
No problem, all too easy to happen with NTFS permissions... the other classic being an account not in the correct share permissions (e.g. because you use a specific group or "domain users".

Steve
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.