Batch file does not run through Task Scheduler in Win Server 2008 R2

Hi.  I created the embedded batch script to delete and refresh some reports on a server share.  Daily process is to overwrite current day reports in the AM through a separate report write.  The batch is to run at the end of the day to delete previous day's reports and copy current day's reports to previous day folder.  This allows me to keep a rolling two days of report data.

My batch file executes likes it should if run manually.  I created a scheduled task over this batch file though and it looks like it runs but never executes and finally just times out at the task max timer.  Not sure what I'm missing.  

task is assigned to the same user that I signed on with to run the file manually.  Batch file exists on same server as the task.  user has plenty of rights to get to the file...  

TPRptCopy-Daily.txt
LVL 7
valmaticAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NVITEnd-user supportCommented:
Task Action options should be similar setup to...
- Program/script: cmd
- Add arguments: /c c:\folder\batfilename.bat

Please verify
oBdACommented:
The issue is that "cd" doesn't change the drive; only "cd /d ..." changes the drive and the path.
But there's no need for the "cd" anyway, just pass the full path to "del" and copy.
Then if S: is a mapped drive, replace it with the UNC.
@ECHO OFF
setlocal
::This script will ensure we always have two days of Thruput Priority Reports available in the event Thruput hits an error and data is not synced properly

set BaseFolder=S:\_Mfg-Production Shared\THRUPUT Reports\WC Priority
DEL "%BaseFolder%\Previous_Day_Reports\*.PDF"
COPY "%BaseFolder%\*.PDF" "%BaseFolder%\Previous_Day_Reports"

set BaseFolder=S:\_Purchasing Shared\01_Thruput Reports
DEL "%BaseFolder%\Previous_Day_Reports\*.PDF"
COPY "%BaseFolder%\*.PDF" "%BaseFolder%\Previous_Day_Reports"

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mohammed KhawajaManager - Infrastructure:  Information TechnologyCommented:
If you are running the command to run as a domain user and S: drive is a mapped drive, ensure to add it to your batch file.  Below would be batch file you would run:

@ECHO OFF
::This script will ensure we always have two days of Thruput Priority Reports available in the event Thruput hits an error and data is not synced properly

net use s: /del
net use s: \\servername\sharename
s:
CD \_Mfg-Production Shared\THRUPUT Reports\WC Priority
DEL Previous_Day_Reports\*.PDF
COPY *.PDF Previous_Day_Reports

CD S:\_Purchasing Shared\01_Thruput Reports
DEL Previous_Day_Reports\*.PDF
COPY *.PDF Previous_Day_Reports
valmaticAuthor Commented:
Thanks for the quick input on this to all of you.  I couldn't get the 1st solution to work but 2nd worked perfectly.
Bill PrewIT / Software Engineering ConsultantCommented:
Glad you got a solution.  Just as a learning example, you can also simplify that a little to reduce the replicated code by looping, take a look at this and see if it makes sense.

@echo off
setlocal
REM This script will ensure we always have two days of Thruput Priority Reports available in the event Thruput hits an error and data is not synced properly

set BaseFolders="S:\_Mfg-Production Shared\THRUPUT Reports\WC Priority","S:\_Purchasing Shared\01_Thruput Reports"
set ArchiveFolder=Previous_Day_Reports

for %%F in (%BaseFolders%) do (
    del /q /y "%%~F\%ArchiveFolder%\*.PDF"
    copy "%%~F\*.PDF" "%%~F\%ArchiveFolder%"
)

Open in new window

~bp
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.