View Full Version : vbscript/batch file gurus - how do I tell if a job is stuck?
How do I tell if a batch file is taking too long?
I have a script that runs every so often from cron (nncron in Windows), and if it gets stuck it holds up all the jobs.
Ideally I'd like to send out an alert or have it kill itself and restart if it's taking too long.
This is in Windows 2000 server.
Anyone?
There has to be something simple in Windows batch files or vbscript?
n6hcm
02-19-2008, 04:22 AM
How do I tell if a batch file is taking too long?
I have a script that runs every so often from cron (nncron in Windows), and if it gets stuck it holds up all the jobs.
Ideally I'd like to send out an alert or have it kill itself and restart if it's taking too long.
This is in Windows 2000 server.
if you were running it from "Scheduled Tasks" there's a box you can check to have the job clobbered if it runs too long ... a bit ham-fisted but it does work.
How do I tell if a batch file is taking too long?
I have a script that runs every so often from cron (nncron in Windows), and if it gets stuck it holds up all the jobs.
Ideally I'd like to send out an alert or have it kill itself and restart if it's taking too long.
This is in Windows 2000 server.
if you were running it from "Scheduled Tasks" there's a box you can check to have the job clobbered if it runs too long ... a bit ham-fisted but it does work.
Hmm. I should try that.
I think it uses some 3rd party cron though.
I thought there was maybe a while or some other similar statement I could use.
kc2orw
02-19-2008, 02:02 PM
You could look at this WMI sample here, I stayed away from WMI after being involved in a project that used it, oogly stuff :wall:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "c:\progra~1\someexe.exe", 1, True
Set WshShell = Nothing
Wscript.Sleep 5000
set svc=getobject("winmgmts:root\cimv2")
sQuery="select * from win32_process where name='exename.exe'"
set cproc=svc.execquery(sQuery)
iniproc=cproc.count 'it can be more than 1
Do While iniproc = 1
wscript.sleep 5000
set svc=getobject("winmgmts:root\cimv2")
sQuery="select * from win32_process where name='exename.exe'"
set cproc=svc.execquery(sQuery)
iniproc=cproc.count
Loop
set cproc=nothing
set svc=nothing
Try it maybe it will work, reliably enough, for you. :think
PS: Shoot Windows 2000 might not have WMI installed by default :doh:
That box is being decommissioned anyway, but as it is, the network hiccups are causing an FTP job to stall every night.
We have no one on our staff, certainly no one on mine that really knows how to do anything with these windows boxes.
I'll try using WMI, maybe I can rewrite the script.
kc2orw
02-20-2008, 07:52 PM
That box is being decommissioned anyway, but as it is, the network hiccups are causing an FTP job to stall every night.
We have no one on our staff, certainly no one on mine that really knows how to do anything with these windows boxes.
I'll try using WMI, maybe I can rewrite the script.
Here is the example of killing a process through WMI
' ProcessKillLocal.vbs
' Sample VBScript to kill a program
' Author Guy Thomas http://computerperformance.co.uk/
' Version 2.7 - December 2005
' ------------------------ -------------------------------'
Option Explicit
Dim objWMIService, objProcess, colProcess
Dim strComputer, strProcessKill
strComputer = "."
strProcessKill = "'calc.exe'"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & strProcessKill )
For Each objProcess in colProcess
objProcess.Terminate()
Next
WSCript.Echo "Just killed process " & strProcessKill _
& " on " & strComputer
WScript.Quit
' End of WMI Example of a Kill Process
Combining the two should get you something that works...
n6hcm
02-22-2008, 05:56 AM
if you were running it from "Scheduled Tasks" there's a box you can check to have the job clobbered if it runs too long ... a bit ham-fisted but it does work.
Hmm. I should try that.
I think it uses some 3rd party cron though.
I thought there was maybe a while or some other similar statement I could use.
oh, i'm sure there is. i don't know it--i'm shovelling coal into the windoze boxes i have until our processing is rejiggered to support linux.
Powered by vBulletin® Version 4.1.12 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.