Solved

DOS batch script to check if schtasks are working or not

Posted on 2014-11-20
8
403 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
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
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

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

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

Suggested Solutions

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
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 …

734 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