Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2005-03-15 : 09:12:19
|
Add into your job you want to time-limit and stop automaticallythe following Active Script (VBS) as the job's 1st step:================================================job_killer_script = "D:\job_killer.vbs"this_job_name = "myJob"time_limit_secs = "20"os_process_to_kill = "N\A"Set o = CreateObject("WScript.Shell")o.Run """" & job_killer_script & """ """ & this_job_name & """ " & _time_limit_secs & " """ & Now & """ """ & os_process_to_kill & """"Set o = Nothing================================================In red the only parameters you need to change. That's all.This is D:\job_killer.vbs script which is invoked (asynchronously) from the job's 1st,controlling, step. It's ready to use and you need no to change anything in it. Onlycheck its colored lines. And, of course, this script can be invoked simultaneously byany number of different started jobs. Hope, kill.exe (rkill.exe in win xp) is in its rightplace, i.e., in %SystemRoot% folder.================================================Option ExplicitOn Error Resume NextDim o, s, j, jd, jtDim job_name, time_limit_secs, step1_dt, os_process_to_killWith WScriptjob_name = .Arguments(0)time_limit_secs = .Arguments(1)step1_dt = .Arguments(2)os_process_to_kill = .Arguments(3)End WithWScript.Sleep 1000 * time_limit_secsSet s = CreateObject("SQLDMO.SQLServer")Set j = CreateObject("SQLDMO.Job")s.LoginSecure = Trues.Connect "."Set j = s.JobServer.Jobs(job_name)jd = j.LastRunDatejt = Right("00000" & j.LastRunTime, 6)'''this is for mdy system date format:jd = Mid(jd, 5, 2) & " " & Right(jd, 2) & " " & Left(jd, 4)'''this is for dmy system date format:'''jd = Right(jd, 2) & " " & Mid(jd, 5, 2) & " " & Left(jd, 4)jt = Left(jt, 2) & ":" & Mid(jt, 3, 2) & ":" & Right(jt, 2)If DateDiff("s", CDate(jd & " " & jt), CDate(step1_dt)) > 5 ThenIf os_process_to_kill <> "N\A" ThenSet o = CreateObject("WScript.Shell")o.Run "kill -f " & os_process_to_kill, , TrueSet o = NothingEnd Ifj.StopEnd Ifs.DisConnectSet j = NothingSet s = Nothing================================================Sample of usage:suppose you have a job named "My silly job" with this silly T-SQL step:exec master..xp_cmdshell 'calc.exe', no_outputwaitfor delay '555:55:55'and you want to time-limit this "job" to 10 seconds of running.Then parameters of its 1st (controlling) step should be:job_killer_script = "D:\job_killer.vbs"this_job_name = "My silly job"time_limit_secs = "10"os_process_to_kill = "calc.exe" |
|
|
|
|
|
|