Solved

Task Scheduler not executing a job (starts and instantly stops)

Posted on 2007-03-28
18
705 Views
Last Modified: 2012-06-27
I am attempting to use Task Scheduler on a Server 2003 to do backups to a drive on the network.  The job runs fine if I right click and then click on "run" BUT it does not execute at all from within the Task Scheduler.

The log:
"BackupDBsToKDsMachine.job" (BackupDBsToKDsMachine.bat)
      Started 3/28/2007 2:00:00 AM
"BackupDBsToKDsMachine.job" (BackupDBsToKDsMachine.bat)
      Finished 3/28/2007 2:00:00 AM
      Result: The task completed with an exit code of (0).

The batch job:
cd E:\

robocopy E:\robocopybackup09\ E:\robocopybackup10 /E /w:1 /r:3 /V /XO

rmdir E:\robocopybackup09 /S /Q

rename E:\robocopybackup08 robocopybackup09
rename E:\robocopybackup07 robocopybackup08
rename E:\robocopybackup06 robocopybackup07
rename E:\robocopybackup05 robocopybackup06
rename E:\robocopybackup04 robocopybackup05
rename E:\robocopybackup03 robocopybackup04
rename E:\robocopybackup02 robocopybackup03
rename E:\robocopybackup01 robocopybackup02

md E:\robocopybackup01

cd C:\

robocopy c:\LIVEAccessDBs\ "E:\robocopybackup01" /E /w:1 /r:3 /XD Windows /XD ClientApps /XF Pagefile.sys /XF NTUSER.DAT /V /XO /Purge


The idea is to have a slowly rotating set of backups and renaming is a much quicker option than doing multiple copies that would otherwise be required.  Again, it works with "run" but not via the task scheduler.

I am setting this up via RDT but that shouldn't make any difference right?  Use a member of the admin group as the user name and the correct password for that user.

Several other jobs run during the night with no problem.  None run at the same time.
0
Comment
Question by:michaelmccomb
  • 10
  • 6
  • 2
18 Comments
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
I think it may be in the way the schedule is setup - try changing the 'run' line in the task to read
cmd /c x:\pathtobatchfile\batchfile.bat
0
 

Author Comment

by:michaelmccomb
Comment Utility
i do not understand that suggestion... i am setting this up by going into "task scheduler", browsing to the batch file and then setting up the weekly times that I wish this job to run...  2AM;Tue,Wed,Thr & Fri (a different and weekly runs on Sat), i tell it it wake the computer and ignor all battery considerations... no expiration date on schedule duration

I guess that I do not understand the 'run' line or where to insert the "cmd /c"  is your suggestion related to the dos prompt?
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
Yes, I've found some batch files that didn't work properly, unless I prefaced them with a call to the command interpreter.
So, open up your task details (Start->Run->%systemroot%\tasks)
Double-click the task, and instead of
"c:\path to file\myfile.bat"
in the run line, use:
cmd /c "c:\path to file\myfile.bat"
(start in can be left blank, or point to %systemroo%\system32)
0
 

Author Comment

by:michaelmccomb
Comment Utility
a half dozen other jobs run (not at the same time) without problem...  one of them repeats every ten minutes from 7AM to 7PM and has no trouble at all...  could some sort of networking delay be responsible for the trouble and is there some way to get the job to pause if that IS the case
0
 

Author Comment

by:michaelmccomb
Comment Utility
thank you, i will try that...  it does seem to be working now...  i rescheduled the task for 1 minute from now after making the change you suggested and it ran...  i'll leave this open until tomorrow to be certain that it runs this evening but as i say it appears that you have fixed my problem....  would sticking in the "cmd /c" be a good thing to do in general (no particular drawbacks/cures problems)?  Thank you very much!
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
no drawbacks, no.
I havent put my finger on the why yet...but glad its working for you...
0
 
LVL 43

Expert Comment

by:Steve Knight
Comment Utility
BTW if that doesn't work is E: a local drive or drive mapped as the logged in user?  If it is a network drive you might need to add a net use to the top of the script or use the UNC instead.

Steve
0
 

Author Comment

by:michaelmccomb
Comment Utility
DRAT!!!  It did not go.  Same symptom....  starts but then stops instantly.  "net use"???  the network drive it is going to is persistently mapped on the server where the batch job is running.  Having to use "cmd c" would seem redundant so perhaps "net use" would fall into the same category.  None of this seems to make much sense.
0
 

Author Comment

by:michaelmccomb
Comment Utility
I just set the job ahead one minute and then sat there and watched it run exactly as it did yesterday when I ran the test.  So I am asking myself what is wrong with 2:00AM without much of an answer BUT I have now changed the job schedule to run the batch at 3:15AM to see if that fixes the problem.  Something is seemingly very strange here.  Rebooted the server about three days ago just in case something was hosed at a deeper level.
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
Q: Are you logging off, or is the console being locked?
0
 

Author Comment

by:michaelmccomb
Comment Utility
i AM logging off and but "locked", not beyond normal passworded login protection...  other jobs do run
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
You're using an admin account, correct?  With network access?
Try using the /IT parameter in your scheduled task (from the command line) - the equivalent, I believe of "Interactive" checkbox in the gui version...
0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 500 total points
Comment Utility
The drive being persistently mapped as E: makes no difference as it is not mapped for the scheduled task.  Add net use e: \\server\share /persistent:no to the top of your script and try again.  You can add credentials to the line if needed, e.g. net use c: \\server\share /user:username password

As an example if you schedule a task to run cmd.exe you should find it knows nothing of the E: drive - if it is the same user account it may, (but I'm not sure), but only if the same user is already logged in at the console.

Steve
0
 

Author Comment

by:michaelmccomb
Comment Utility
Alright  i have now mapped the drive with the "net use e:\\ser..." phrase.  Yesterday the job would run if I was logged in and perhaps that is because the logged in admin user was also the user running the batch job.  Early tomorrow morning the job will run once again with the admin user not interactively logged in.  I did a little test running a batch job via the scheduler one minute later and having the interactive user off... the start and stop times for the batch job were not identical indicating that the job ran successfully.  Back on tomorrow to report on the results for the backup job.
0
 

Author Comment

by:michaelmccomb
Comment Utility
The same error is occuring... zero execution time indicated and nothing is accomplished

***Scheduled Tasks / Advanced / View Log:OutPut***
"BackupDBsToKDsMachine.job" (cmd)
      Started 3/30/2007 2:00:00 AM
"BackupDBsToKDsMachine.job" (cmd)
      Finished 3/30/2007 2:00:00 AM
      Result: The task completed with an exit code of (0).


***BackupDBsToKDsMachine.job / Properties / Run line***
cmd /c "C:\BatchJobs\BackupDBsToKDsMachine.bat"


***Text of batch file***
net use e: \\\\Kevinsws\RoboBackups /persistent:no

cd E:\

robocopy E:\robocopybackup09\ E:\robocopybackup10 /E /w:1 /r:3 /V /XO

rmdir E:\robocopybackup09 /S /Q

rename E:\robocopybackup08 robocopybackup09
rename E:\robocopybackup07 robocopybackup08
rename E:\robocopybackup06 robocopybackup07
rename E:\robocopybackup05 robocopybackup06
rename E:\robocopybackup04 robocopybackup05
rename E:\robocopybackup03 robocopybackup04
rename E:\robocopybackup02 robocopybackup03
rename E:\robocopybackup01 robocopybackup02

md E:\robocopybackup01

cd C:\

robocopy c:\LIVEAccessDBs\ "E:\robocopybackup01" /E /w:1 /r:3 /XD Windows /XD ClientApps /XF Pagefile.sys /XF NTUSER.DAT /V /XO /Purge


Still running perfectly by hand...  right click on task /  run

??????

0
 

Author Comment

by:michaelmccomb
Comment Utility
ok, so i am asking myself what is up with the \\\\ in the "net use" sequence of the run statement.  I do not know how but I MUST be the one who put it in there.... I have now backed it off to only
"net use e: \\Kevinsws\RoboBackups /persistent:no"

it will be over the weekend before I will know if this works
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
*I have made worse boo-boos than that...don't sweat it.
Good luck and have a nice weekend. :^)
0
 

Author Comment

by:michaelmccomb
Comment Utility
Ok, i've flipped it on and off a couple of times and it seems to be that the "net use" suggestion is the one that straightened things out..  I shall remember this and the "cmd c" line in all future batch jobs
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now