Solved

DOS batch script to check if schtasks are working or not

Posted on 2014-11-20
8
414 Views
Last Modified: 2014-12-06
Can anyone help..

I am writing a DOS batch script which calls a command called schtasks to initiate a dos batch script... however I would like some error checking involved to check the following:-

1. if the schedule task fails to start it errors.  - e.g. task failed to start
2. if the schedule task starts but fails to complete, it errors - e.g. task failed to complete
3. if the schedule task completes - e.g. task completed successfully
0
Comment
Question by:rakkad
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 24

Accepted Solution

by:
NVIT earned 500 total points
ID: 40455688
Does this help?
schtasks /query /fo LIST /v /tn "Name of task" | find /i "Last Result:"

Open in new window

0
 
LVL 24

Expert Comment

by:NVIT
ID: 40455738
Or...
for /f "tokens=1,2 delims=:" %%A in ('schtasks /query /v /fo list /tn "Name of task" ^| find /i "last result"') do (call :Next %%B)
goto :eof

:Next
for %%A in (%1) do echo %%A

Open in new window

0
 
LVL 70

Expert Comment

by:Qlemo
ID: 40456326
NewVillageIT, why that complicated? And it is not removing the white space ...
for /f "tokens=3 delims=	: " %%A in ('schtasks /query /v /fo list ^| find /i "last result"') do @echo %%A

Open in new window

However, all suggestions up to now only display the last result error code. And it won't get better, because the only fact you can know is that 0 means "ok". Any other code reflects an issue, but you won't know more as long as you did not test yourself in which case which last result value is shown.
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 24

Expert Comment

by:NVIT
ID: 40456536
Qlemo... What's a simpler way to get the task result? I'd appreciate your help.
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 40456992
See my code.%%A contains the raw value we can assign to a var to check for known result codes.
0
 

Author Closing Comment

by:rakkad
ID: 40483243
This task worked
0
 
LVL 24

Expert Comment

by:NVIT
ID: 40483409
Rakkad... I glad it worked for you.
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 40484606
Objection. http:#a40456326  shows a better way to get the result code (because you do not get a string containing it, but the code itself). The following comments show that you were interested in that.
And I explained what you can expect at most. So I would have expected at least an equal share of points, if not the majority.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

617 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