All questions related to installations, configurations and maintenance of Advanced Host Monitor (including additional tools such as RMA for Windows, RMA Manager, Web Servie, RCC).
remilner82
Posts: 14 Joined: Mon Aug 16, 2010 8:42 am
Post
by remilner82 » Wed Aug 18, 2010 9:29 am
Hello
I am trying to run this vbscript as a Shell script so that I can pass the computer name to the script to test any server I want. However, when I run the script I get "Script started, no results received".
Any help anyone can give would be greatly appreciated.
Code: Select all
Option Explicit
const statusAlive = "Host is alive:"
const statusDead = "No answer:"
const statusUnknown = "Unknown:"
const statusNotResolved = "Unknown host:"
const statusOk = "Ok:"
const statusBad = "Bad:"
const statusBadContents = "Bad contents:"
dim strComputer, objArgs, objWMIService, colOperatingSystems, dtmBootup, dtmLastBootupTime, dtmSystemUptime, objOS
Set objArgs = WScript.Arguments
strComputer = "."
if objArgs.Count>0 then
strComputer = objArgs(0)
end if
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOS in colOperatingSystems
dtmBootup = objOS.LastBootUpTime
dtmLastBootupTime = WMIDateStringToDate(dtmBootup)
performtest = statusOk & dtmLastBootupTime
Next
Function WMIDateStringToDate(dtmBootup)
WMIDateStringToDate = CDate(Mid(dtmBootup, 5, 2) & "/" & _
Mid(dtmBootup, 7, 2) & "/" & Left(dtmBootup, 4) _
& " " & Mid (dtmBootup, 9, 2) & ":" & _
Mid(dtmBootup, 11, 2) & ":" & Mid(dtmBootup,13, 2))
End Function
KS-Soft
Posts: 13012 Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:
Post
by KS-Soft » Wed Aug 18, 2010 6:37 pm
Shell Script should write result into standard output, your script does not perform such operation.
You may modify script a little...
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 strComputer, objArgs, objWMIService, colOperatingSystems, dtmBootup, dtmLastBootupTime, objOS
Set objArgs = WScript.Arguments
strComputer = "."
if objArgs.Count>0 then
strComputer = objArgs(0)
end if
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOS in colOperatingSystems
dtmBootup = objOS.LastBootUpTime
dtmLastBootupTime = WMIDateStringToDate(dtmBootup)
WScript.StdOut.Write statusOk & dtmLastBootupTime
Next
Function WMIDateStringToDate(dtmBootup)
WMIDateStringToDate = CDate(Mid(dtmBootup, 5, 2) & "/" _
& Mid(dtmBootup, 7, 2) & "/" & Left(dtmBootup, 4) & " " _
& Mid (dtmBootup, 9, 2) & ":" & Mid(dtmBootup, 11, 2) & ":" _
& Mid(dtmBootup,13, 2))
End Function
Please note this string
WScript.StdOut.Write statusOk & dtmLastBootupTime
it returns test status and result to HostMonitor
Regards
Alex
remilner82
Posts: 14 Joined: Mon Aug 16, 2010 8:42 am
Post
by remilner82 » Thu Aug 19, 2010 1:47 am
Thanks for your reply. You have pointed me in the right direction and I modified the script slightly and I have it working perfectly now.
Feel free to use the code:
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 strComputer, performtest, objArgs, objWMIService, colOperatingSystems, dtmBootup, dtmLastBootupTime, dtmSystemUptime, objOS
Set objArgs = WScript.Arguments
strComputer = "."
if objArgs.Count>0 then
strComputer = objArgs(0)
end if
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOS in colOperatingSystems
dtmBootup = objOS.LastBootUpTime
dtmLastBootupTime = WMIDateStringToDate(dtmBootup)
Next
Wscript.stdout.write statusOK
WScript.StdOut.Write dtmLastBootupTime
Function WMIDateStringToDate(dtmBootup)
WMIDateStringToDate = CDate(Mid(dtmBootup, 5, 2) & "/" & _
Mid(dtmBootup, 7, 2) & "/" & Left(dtmBootup, 4) _
& " " & Mid (dtmBootup, 9, 2) & ":" & _
Mid(dtmBootup, 11, 2) & ":" & Mid(dtmBootup,13, 2))
End Function