Solved

DOS batch script to check if schtasks are working or not

Posted on 2014-11-20
8
382 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
  • 4
  • 3
8 Comments
 
LVL 23

Accepted Solution

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

Open in new window

0
 
LVL 23

Expert Comment

by:NVIT
Comment Utility
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 68

Expert Comment

by:Qlemo
Comment Utility
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
 
LVL 23

Expert Comment

by:NVIT
Comment Utility
Qlemo... What's a simpler way to get the task result? I'd appreciate your help.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
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
Comment Utility
This task worked
0
 
LVL 23

Expert Comment

by:NVIT
Comment Utility
Rakkad... I glad it worked for you.
0
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

771 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

10 Experts available now in Live!

Get 1:1 Help Now