Reminders

Monitor Schtasks from vbscript - Active server script

2 years ago
OfflinePhoto of Marcos Chamma
Marcos Chamma

Dear,

I am trying to create active server script to monitor the results of Windows 2008 Scheduled tasks.

From my Desktop I have a VBS that works fine.

When I put this vbscript into an active server script it says: Error: The script timed out because it exceeded 10 seconds, I tried 60 seconds.

Script:

Dim TasksArr(100000)

Dim WshShell, oExec

LastLineStart = "Power Management: "

Set WshShell = CreateObject("WScript.Shell")

DosCommand = "schtasks /query /s srv003 /tn \Microsoft\Windows\Backup /FO List /v"

'The tool is launched Set oExec = WshShell.Exec(DosCommand)

On Error Resume Next

'We scan and display the command output flow

Do While oExec.StdOut.AtEndOfStream <> True

         i = 0

         Line =   oExec.StdOut.ReadLine

          If Not IsNull(Line) Then

             Do While Left(Line,18) <> LastLineStart

                 NewLine = GetData(Line)

                 SpaceIndex = InStr(NewLine,": ")

                 TasksArr(i) = Mid(NewLine,SpaceIndex + 2)

                 Line = oExec.StdOut.ReadLine

                 i = i + 1

             Loop

            If TasksArr(8) = 0 Then

Context.SetResult 0, "No error"

                 LastRun = "Succeeded"

            Else

Context.SetResult 1, "Error"

                 LastRun = "Failed"

             End If

          ' WScript.Echo TasksArr(1)  & TasksArr(2) & "#" & TasksArr(3) & "#" & TasksArr(4) & "#" & TasksArr(5) & "#" & TasksArr(8) & "#" & TasksArr(19) & "#" & LastRun

          End If

          Loop

'Replacing All WhiteSpaces With one

Function GetData(strSource)    With CreateObject("vbscript.regexp")        .Global = True         .Pattern = "\s+"         NoSpaces = .Replace(strSource, " ")         GetData = NoSpaces '        GetData = Split(NoSpaces, " ")     End With End Function

 

Can you please help me?

Concluded

1 Conclusion:

OfflinePhoto of Marcos Chamma Marcos Chamma said 2 years ago

Hi Friends,

I found the problem, I had to add an Exit Do right after the End If Wscript.Echo Tasks Arr...

Now it is working.

Thanks for the suggestions.

13 Replies

OfflinePhoto of Willem de Groot Willem de Groot said 2 years ago

Do you have some more information in the Eventviewer?
May there be an Credentials Problem, If you run this script int the Scheduled Tasks, it will not run under your Acount. also don't run it from your Desktop , move it to a place that is not related to your acount.


OfflinePhoto of Marcos Chamma Marcos Chamma said 2 years ago

Thanks, I noticed that on my machine I can run the script without any problem.

When I run the same script logged on with the same account it does not runs OK.

Any other ideas?

Thanks


OfflinePhoto of Paul Byers Paul Byers said 2 years ago

the account you are using to monitor will need rights on the remote device. that would be the easiest fix


OfflinePhoto of Marcos Chamma Marcos Chamma said 2 years ago

I just noticed the following: When I run the script on a english machine the vbscript runs fine.

Unfortunatelly the whatsupgold machine is not english OS and all non-english machines that I run the script it doesn´t complete fine.

Any ideas?


OfflinePhoto of Marcos Chamma Marcos Chamma said 2 years ago

Hi!

Now I can run the script ouside Whatsup Gold, the problem was: LastLineStart = "Power Management: " This should be translated to Brazillian portuguese.

Now I can run the script outside Whatsup, but when I click TEST on Active Monitor Library it returns Timeout.

The account used to start WhatsupGold is a domain admins account.


OfflinePhoto of WhatsUp Guru (Jason Williams) WhatsUp Guru (Jason Williams) said 2 years ago

Moved to the appropriate forum.


OfflinePhoto of Marcos Chamma Marcos Chamma said 2 years ago

Hi Friends,

This is not solved yet...

Now I can run the vbscript outside Whatsupgold, when I try the Test function on Active Monitor Library it returns TIMEOUT.

Any ideas please?


OfflinePhoto of Paul Byers Paul Byers said 2 years ago

apologies, I am not familiar enough on running VBscripts on non-english machines.  My first guess would be privledges.  when pushing test it uses the account that is loged in to the WUG server.  When running if you are not passing credentials and using those it would use the account WUG is running under.


OfflinePhoto of Marcos Chamma Marcos Chamma said 2 years ago

Hi Paul,

The account used to start IPSwitch Service Control Manager is a Domain Admin Account and the user logged in to WUG Server is a domain admin account.

Thanks

 


OfflinePhoto of Marcos Chamma Marcos Chamma said 2 years ago

Hi Friends,

I found the problem, I had to add an Exit Do right after the End If Wscript.Echo Tasks Arr...

Now it is working.

Thanks for the suggestions.


OfflinePhoto of Service Informatique Service Informatique said 21 months ago

I have modified the script to :
- Get automatically the server name from WhatsUP DeviceID
- Allow script to work in standalone script and WhatsUP script
- Enable a debug mode
- Declare all variables


OfflinePhoto of Service Informatique Service Informatique said 21 months ago

I attach the script in a text file on this post....
MonitorScheduleTaskResult.txt - 11 ko

Attachments

 

Would you like to comment?

You must be a member. Sign In if you are already a member.

  • 2,406 views
  • 3 versions
  • 13 replies
  • 5 followers
     
Avg. Rating:
Rating: 5out of5Igloo.Common.ObjectUserInfo
Posted By:
Marcos Chamma
 
July 6, 2012

Related Content

    Search this area

    About this forum

    • 289k views
    • 3407 topics
    • 63 followers
       

    Post questions and find answers for all things related to the Standard and Premium Editions of WhatsUp gold.


    Viewed 2,406 times