Scheduled Tasks check

If you have information, script, utility, or idea that can be useful for HostMonitor community, you welcome to share information in this forum.
KS-Soft
Posts: 12869
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Scheduled Tasks check

Post by KS-Soft »

Utility that may check status of scheduled tasks available at
www.ks-soft.net/download/utils/schtaskcheck.zip
This is command line utility that can be used with Shell Script test method
http://www.ks-soft.net/hostmon.eng/mfra ... m#chkShell

Usage: schtaskcheck.exe -task:<task_name> -timeframe:<time_interval> [-host:<hostname>] [-user:<username>] [-pswd:<password>] [-ignoreres]

There are 2 mandatory command line parameters:
-task: Scheduled task name
-timeframe: Specifies time interval when the task was expected to be excuted. Interval specified in minutes. E.g. -timeframe:60 means scheduled task had to be executed within last hour.
Also there are several predefined constants you may use: today, yesterday, this_week, last_week, this_month and last_month

3 optional parameters:
-host: Specifies the name or IP address of a remote computer, with or without backslash characters. If omitted, utility checks the local computer
-user: Run the utility with the permission of the specified user account
-pswd: Specifies the password of the user account that is specified in the -user parameter
-ignoreres: This option suppresses additional check for last exit code. If omitted, utility checks task exit code and returns Bad status when exitcode<>0

Examples:
schtaskcheck -task:"Daily Backup" -timeframe:120
schtaskcheck -task:check_log -timeframe:today -host:Second_Server
schtaskcheck -task:check_log -timeframe:today -host:ftp.corp.com -user:admin
schtaskcheck -task:AV_update -timeframe:yesterday -host:192.168.1.100 -user:dsma -pswd:secretphrase -ignoreres

Regards
Alex
vpavel
Posts: 12
Joined: Tue Oct 30, 2007 9:03 am

Post by vpavel »

When i am trying to monitor schedule tasks execution in different time zone , i receive BAD result becouse of time difference.It doesn't work even after upgrade to last 7.24 version.I use custom folder GMT setting.But shell script execute test with local time :(

[11:40:06 AM] Script executed, correct result received:
----------
- Status: Bad
- Reply: 15.07.2008 19:38:00 Last Result : 1

Can you fix it please ?
KS-Soft
Posts: 12869
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

Folder-level "GMT offset" option has nothing to do with external utilities like schtaskcheck.exe. This option affects GUI, reports, schedules.

In many cases you can adjust "timeframe" parameter of the test to make it work. However we added new option "-remotegmt" that allows you to specify GMT offset on target server (minutes).
E.g.
-remotegmt:-300 specified Easter Time zone (GMT -05:00)
-remotegmt:+540 specified Tokyo/Seoul time (GMT +09:00)

New version of the utility available at www.ks-soft.net/download/utils/schtaskcheck.zip

Regards
Alex
vpavel
Posts: 12
Joined: Tue Oct 30, 2007 9:03 am

Post by vpavel »

thank you :P
User avatar
greyhat64
Posts: 246
Joined: Fri Mar 14, 2008 9:10 am
Location: USA

Post by greyhat64 »

Alex,
Thanks! I had written a script to do this via WMI, but I think I like this better.
Though, if you keep this up, I'm gonna need to occupy my time doing something other that script writing. :lol:
Marcel_vrinds
Posts: 2
Joined: Wed Jan 13, 2010 1:53 pm

Post by Marcel_vrinds »

Hi,

I am using this tool, but i get "error: script returns no results"

Started schtaskcheck on the active rma side. If i start a cmd screen on the rma side, i get; ScriptRes:Bad:13-1-2010 19:50:28. So that is good! but why don't i get the info in the hostmonitor.

Can someone help me.

Cheers!
KS-Soft
Posts: 12869
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

What version of HostMonitor do you use? RMA?
Windows version on system where RMA is running? Service Pack?
Can this agent perform any other Shell Script test without problem?

Regards
Aex
Marcel_vrinds
Posts: 2
Joined: Wed Jan 13, 2010 1:53 pm

Post by Marcel_vrinds »

Hi

Thanks for the quick reaction

Hostmonitor 8.14 and RMA 3.35

Hostmonitor is running on sbs2003 with all sp's and updates
RMA is running on server 2003 r2 with all updates

This is the first shell script that i am using.

Thanks,

Marcel
KS-Soft
Posts: 12869
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

Sorry, I missed your answer.
Could you please try to setup some other Shell Script test? HostMonitor provides several samples, you may use simply VB or Java script, even BAT file.
This way we will know is problem related to schtaskcheck.exe utility or there is some problem related to external program execution.

What account do you use to run agent?

Regards
Alex
YG
Posts: 4
Joined: Fri Sep 03, 2010 12:23 pm

If it's not to much to ask

Post by YG »

I am a newbie admin and I am in need of some help on the Scheduled task check test.
Would somebody be so kind to give me an example of the script to check if the scheduled task with the name “File Transfer to AOD“ completed by a certain time ( for example: it starts at 12AM Eastern Standard Time and has to be completed by 5AM ). No matter what I do I can’t make it work.
Your help is greatly appreciated. Thank you in advance.
KS-Soft
Posts: 12869
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

Have you setup Shell Script test to be executed every day at 5:01AM using command for the script like
schtaskcheck.exe "-task:File Transfer to AOD“ -timeframe:today -host:hostname -user:username -pswd:password
I can’t make it work.
Could you please be more specific? What exactly parameters for the script do you use and what exactly is test result (status and reply)?

Regards
Alex
YG
Posts: 4
Joined: Fri Sep 03, 2010 12:23 pm

Post by YG »

Thank you for your help. I will try that.
The problem was after I clicked on the "let's try" it was not recognizing the scheduled task name.
I can see now that you put the " before -task, I had it after -task like this:
-task "File transfer to AOD" because that's how it was shown in the example in the beginning of the forum. I will try it your way let you know what happened.
YG
Posts: 4
Joined: Fri Sep 03, 2010 12:23 pm

Post by YG »

It appears to be a Windows Server 2008 R2 issue. The script runs fine against Server 2003 Scheduled tasks but fails to recognize then on 2008. Any ideas how to use them on 2008 R2 scheduled task?
KS-Soft
Posts: 12869
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

I am afraid we need to create different utility for Windows 2008.
On the other hand, if you need to check local system or you can install RMA on target system, then you may use script like the following

Code: Select all

Option Explicit

const statusAlive       = "scriptRes:Host is alive:"
const statusDead        = "scriptRes:No answer:"
const statusUnknown     = "scriptRes:Unknown:"
const statusNotResolved = "scriptRes:Unknown host:"
const statusOk          = "scriptRes:Ok:"
const statusBad         = "scriptRes:Bad:"
const statusBadContents = "scriptRes:Bad contents:"

Dim objArgs, fnd
fnd = 0
Set objArgs = WScript.Arguments

if objArgs.count <> 2 then
    WScript.StdOut.Write statusUnknown & "2 arguments expected <TaskName> <timeframe>"
End if

Dim service
' Create the TaskService object.
Set service = CreateObject("Schedule.Service")
call service.Connect()

' Get the task folder that contains the tasks. 
Dim rootFolder
Set rootFolder = service.GetFolder("\")
 
Dim taskCollection
Set taskCollection = rootFolder.GetTasks(0)

If taskCollection.Count = 0 Then 
    WScript.StdOut.Write statusUnknown & "No tasks are registered."
Else
    Dim registeredTask
    Dim D1, D1D, Dif
    For Each registeredTask In taskCollection
    if registeredTask.Name = objArgs(0) then
        fnd = fnd + 1
        D1 = registeredTask.LastRunTime
        D1D = CDate(D1)
        Dif = DateDiff("n", D1D, Now())
        if Dif > Int(objArgs(1)) then
            WScript.StdOut.Write statusBad & "Last Run: " & Dif & " min"
        Else
            WScript.StdOut.Write statusOk & "Last Run: " & Dif & " min"
        End If

    End If
    Next

    if fnd = 0 then
        WScript.StdOut.Write statusUnknown & "Task " & objArgs(0) & " NOT found."
    End If
End If
Script requires 2 parameters: taskname and timeframe (specified in minutes). E.g. "File Transfer to AOD" 300
Command line to start script: cmd /c cscript /B /E:VBScript %Script% %Params%

Regards
Alex
KS-Soft
Posts: 12869
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

BTW: We can modify script so it will request data from remote system or you can modify it by yourself (using hostname, login and password parameters for call service.Connect procedure call)

Regards
Alex
Post Reply