Page 1 of 1

Batch job won't run with task scheduler

Posted: 23 Sep 2016 13:11
by chev
Hey guys,
I have a batch job that i set up using windows 2003, :shock: I setup a simple copy command to copy some files over to a mapped directory several times a day. The problem lies when running it through task manager it runs, but doesn't execute the batch file.

Running the code manually in dos works, copy paste... running it through dos and calling the batchfile run's fine as well. The file has two commands to execute, I have even put the absolute path in the dest instead of using a mapped drive.

Xcopy D:\source\*.* Z:\dest\*.* /d /f /y /e /c >> F:\log.txt


I did a test and changed the dest directory to a local drive and it worked with task scheduler.. so looks like it has to do with the mapped drive.. but absolute path didn't work either..
maybe use net user in batch file?
Suggestions.. Thanks

Re: Batch job won't run with task scheduler

Posted: 23 Sep 2016 13:26
by Squashman
Yes you need to use the UNC path and you also have to set a username and password in the task properties for a user that has access to that network resource.

Re: Batch job won't run with task scheduler

Posted: 23 Sep 2016 13:55
by chev
I used the UNC path in the batch file, and yes have the user and password in the task scheduler, the UNC in the batch file didn't work.

are you suggesting I use the net use in the batch file as well as the UNC?

so

net use z:\ path -----> checked in dos
Xcopy D:\source\*.* Z:\dest\absolute_path\*.* /d /f /y /e /c >> F:\log.txt

Re: Batch job won't run with task scheduler

Posted: 23 Sep 2016 14:08
by Squashman
chev wrote:I used the UNC path in the batch file, and yes have the user and password in the task scheduler, the UNC in the batch file didn't work.

I know it works. This is what I do for a living. Data automation. I have 4 servers and 800 automation tasks. Close to 100 of those tasks are Windows Scheduled Tasks running batch files.


chev wrote: are you suggesting I use the net use in the batch file as well as the UNC?
so

net use z:\ path -----> checked in dos
Xcopy D:\source\*.* Z:\dest\absolute_path\*.* /d /f /y /e /c >> F:\log.txt

That works as well. But again you don't even need to assign it a drive letter. You can authenticate with the NET USE command to the UNC path and still use the UNC path in the batch file. I discussed this a while back on the forums.

Re: Batch job won't run with task scheduler

Posted: 23 Sep 2016 14:38
by Squashman
Here is the thread where I talked about using the NET USE command without assigning a drive letter. I have only ever used this method once and I can't remember why. Window Task Scheduler has never failed if I put in the correct credentials for access to the network resource.

viewtopic.php?f=3&t=5247

Re: Batch job won't run with task scheduler

Posted: 24 Sep 2016 07:01
by foxidrive
Squashman wrote:Window Task Scheduler has never failed if I put in the correct credentials for access to the network resource.

That's the key I think. The system account doesn't have access to any network resources.

Re: Batch job won't run with task scheduler

Posted: 26 Sep 2016 11:10
by chev
you guys are absolutely right.. The issue is with the maintenance account that task scheduler has assigned to it doesn't have the correct privs to the share...
Thanks for all the input... Appreciated..

Re: Batch job won't run with task scheduler

Posted: 03 Oct 2016 13:47
by chev
So, I have another issue with this same situation.. again this is windows 2003....You can login and run the jobs manually through task scheduler, works fine. But if you log off the server and in my case the service account the jobs will execute but they won't do the job...

for instance I have my jobs outputted to a log file and they are just copying files off of the server...
Logged in, copy just fine... logged out I get 0 files copied and verified.. :cry:

any ideas, suggestions would be great.. thanks

Re: Batch job won't run with task scheduler

Posted: 03 Oct 2016 14:10
by chev
thinking about it too.. I have other batch files that don't do copies off, that execute just fine... seems like its a problem with xcopy and when the server isn't logged in thats the problem.. is there a special switch maybe that needs to be put into place?

Re: Batch job won't run with task scheduler

Posted: 03 Oct 2016 14:15
by Squashman
chev wrote:thinking about it too.. I have other batch files that don't do copies off, that execute just fine... seems like its a problem with xcopy and when the server isn't logged in thats the problem.. is there a special switch maybe that needs to be put into place?

Just going to reiterate what I already said.
UNC paths.
Username and password configured in the scheduled task that has access to the needed resources.

Re: Batch job won't run with task scheduler

Posted: 04 Oct 2016 07:02
by chev
Squashman wrote:
chev wrote:thinking about it too.. I have other batch files that don't do copies off, that execute just fine... seems like its a problem with xcopy and when the server isn't logged in thats the problem.. is there a special switch maybe that needs to be put into place?

Just going to reiterate what I already said.
UNC paths.
Username and password configured in the scheduled task that has access to the needed resources.



I see your point and I would think if that was the problem when I run the batch jobs manually( with task scheduler) (or scheduled) while logged into the server everything works fine.
When the server is not logged in, the jobs execute, but don't copy the files.. When I say execute, I see in the logfiles that 0 files copied..

Re: Batch job won't run with task scheduler

Posted: 04 Oct 2016 07:21
by Squashman
chev wrote:
Squashman wrote:
chev wrote:thinking about it too.. I have other batch files that don't do copies off, that execute just fine... seems like its a problem with xcopy and when the server isn't logged in thats the problem.. is there a special switch maybe that needs to be put into place?

Just going to reiterate what I already said.
UNC paths.
Username and password configured in the scheduled task that has access to the needed resources.



I see your point and I would think if that was the problem when I run the batch jobs manually( with task scheduler) (or scheduled) while logged into the server everything works fine.
When the server is not logged in, the jobs execute, but don't copy the files.. When I say execute, I see in the logfiles that 0 files copied..

I can't see your batch file and I can't see how your task is configured so I just have to take your word that you have everything setup correctly. But I can tell you from my experience that it does work they way I have described it otherwise my boss would be screaming at me every day that we are not meeting our SLA's (service level agreements) with our clients.

Re: Batch job won't run with task scheduler

Posted: 06 Oct 2016 14:39
by foxidrive
chev wrote: I see your point and I would think if that was the problem when I run the batch jobs manually( with task scheduler) (or scheduled) while logged into the server everything works fine.


That's not the same as running the task without being logged in.
Test Squashman's advice once more.

Re: Batch job won't run with task scheduler

Posted: 06 Oct 2016 21:04
by alexf5
make a new task scheduler is the best choice
i think your old task sch there's no enough user right, may be you have change pass of user or win,