Batch job won't run with task scheduler

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
chev
Posts: 6
Joined: 23 Sep 2016 12:49

Batch job won't run with task scheduler

#1 Post by chev » 23 Sep 2016 13:11

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
Last edited by chev on 23 Sep 2016 13:31, edited 1 time in total.

Squashman
Expert
Posts: 4471
Joined: 23 Dec 2011 13:59

Re: Batch job won't run with task scheduler

#2 Post by Squashman » 23 Sep 2016 13:26

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.

chev
Posts: 6
Joined: 23 Sep 2016 12:49

Re: Batch job won't run with task scheduler

#3 Post by chev » 23 Sep 2016 13:55

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

Squashman
Expert
Posts: 4471
Joined: 23 Dec 2011 13:59

Re: Batch job won't run with task scheduler

#4 Post by Squashman » 23 Sep 2016 14:08

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.

Squashman
Expert
Posts: 4471
Joined: 23 Dec 2011 13:59

Re: Batch job won't run with task scheduler

#5 Post by Squashman » 23 Sep 2016 14:38

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

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch job won't run with task scheduler

#6 Post by foxidrive » 24 Sep 2016 07:01

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.

chev
Posts: 6
Joined: 23 Sep 2016 12:49

Re: Batch job won't run with task scheduler

#7 Post by chev » 26 Sep 2016 11:10

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..

chev
Posts: 6
Joined: 23 Sep 2016 12:49

Re: Batch job won't run with task scheduler

#8 Post by chev » 03 Oct 2016 13:47

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

chev
Posts: 6
Joined: 23 Sep 2016 12:49

Re: Batch job won't run with task scheduler

#9 Post by chev » 03 Oct 2016 14:10

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?

Squashman
Expert
Posts: 4471
Joined: 23 Dec 2011 13:59

Re: Batch job won't run with task scheduler

#10 Post by Squashman » 03 Oct 2016 14:15

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.

chev
Posts: 6
Joined: 23 Sep 2016 12:49

Re: Batch job won't run with task scheduler

#11 Post by chev » 04 Oct 2016 07:02

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..

Squashman
Expert
Posts: 4471
Joined: 23 Dec 2011 13:59

Re: Batch job won't run with task scheduler

#12 Post by Squashman » 04 Oct 2016 07:21

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.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch job won't run with task scheduler

#13 Post by foxidrive » 06 Oct 2016 14:39

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.

alexf5
Posts: 4
Joined: 06 Oct 2016 20:42

Re: Batch job won't run with task scheduler

#14 Post by alexf5 » 06 Oct 2016 21:04

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,

Post Reply