Link to home
Start Free TrialLog in
Avatar of BriantC
BriantC

asked on

Windows Server 2008 Task Scheduler Job status shows running after job is done

I have a task that runs a .bat file to ftp files from one server to another.  It writes events to the Event log about the progress of the job.  The last event it writes is "Job Completed SUCCESSFULLY".

Following are the last lines of the .bat file.
:END
      eventcreate /t information /id 107 /l application /d "%3.zip Get DB Backup Job Completed SUCCESSFULLY."

:BADEND
      net use %1: /delete
      exit

The problem is that even though the processing of the bat file completes, the job status in Task Scheduler shows running and the next night when the task should run, it doesn't launch because its status is still Running.  

I am thinking about changing the trigger to end job if runs longer than 8 hours, but was wondering if anyone has seen this type of issue before.  The job runs under a local ID with admin privileges.  Sometimes it runs fine and ends other times it remains in a running status until I end it manually.

Any ideas?

Thanks!
Avatar of Gary Coltharp
Gary Coltharp
Flag of United States of America image

Why do you not have an exit after your event creation?
Avatar of BriantC
BriantC

ASKER

Because I always want to execute the net use %1: /delete command to unmap the source share drive.

I wonder if the net use /delete is prompting for a Y/N response sometimes.  I'll look to see if there is a noprompt option.
I dont know of any Y/N that would occur on a net use /del.... you could try redirecting the output of the lines of your batch file to a log , ie; >>output.log .... then examining the end of it the next day to see if any errors were trapped.
Avatar of BriantC

ASKER

Good idea gcoltharp!  Below is the output in the .txt file.  

There are open files and/or incomplete directory searches pending on the connection to M:.

Is it OK to continue disconnecting and force them closed? (Y/N) [N]:

Do you know how I can script a response?  The files have already been copied over, compared, and deleted at this point.  It doesn't always hang, only sometimes.  Can I add /noprompt or something to force it to delete the connection everytime?
ASKER CERTIFIED SOLUTION
Avatar of Gary Coltharp
Gary Coltharp
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If that does not work, you can also try:

Echo yes | net use %1: /d

Cheers!
Avatar of BriantC

ASKER

Thanks gcoltharp!

Redirecting the output to the .txt file identified why the job was hanging and adding the /yes after the net use comand appears to have resolved the issue in my limited testing.
Avatar of BriantC

ASKER

Thanks also telczj9 for responding.

I will keep your suggestion in case I encounter the same type of hung state in the future.
Awesome! Happy to help!