valmatic
asked on
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
@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
ASKER
Thanks for the quick input on this to all of you. I couldn't get the 1st solution to work but 2nd worked perfectly.
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%"
)
~bp
- Program/script: cmd
- Add arguments: /c c:\folder\batfilename.bat
Please verify