Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Batch File - Delete Command Failing when run from Task Scheduler

Posted on 2011-04-28
7
Medium Priority
?
1,002 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
0
Comment
Question by:LoveToSpod
  • 3
  • 3
7 Comments
 
LVL 2

Assisted Solution

by:ComputerAidNZ
ComputerAidNZ earned 1000 total points
ID: 35482522
Sounds suspiciouosly like a permissions issue here, you are able to read, write, but not delete - chjeck permissions first.
0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 1000 total points
ID: 35482537
Agreed, permissions does sounds likely.  Is this running as a different user under task scheduler to running it manually (I would presume you have a special account for tasks scheduled?).

What is the error, "access denied", presumably?

Could it be the file is open/in-use otherwise?

The script refers to two directories too, m_baks and mm_baks, is that just a slip of the sanitising copy/paste for here I presume?

Steve
0
 
LVL 43

Assisted Solution

by:Steve Knight
Steve Knight earned 1000 total points
ID: 35482549
Add in before the delete:

dir e:\mm_baks > e:\logfile.txt
del e:\mm_baks\*.bak >> e:\logfile.txt 2>>&1

to capture the output of what happens perhaps into a logfile.

Steve
0
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 

Author Comment

by:LoveToSpod
ID: 35482613
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.
0
 

Author Comment

by:LoveToSpod
ID: 35482836
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


0
 

Author Closing Comment

by:LoveToSpod
ID: 35482848
Top notch, thanks!
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 35482879
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
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Utilizing an array to gracefully append to a list of EmailAddresses
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question