Video Screencast Help
Search Video Help Close Back
to help
New in the Rewards Catalog: Vouchers for "Symantec Technical Specialist" and "Symantec Certified Specialist" exams.

Script to Kill Jobs at a specific time

Updated: 23 May 2010 | 4 comments
Alex Vasquez's picture
0 0 Votes
Login to vote
This issue has been solved. See solution.

Hello all,

I'm working on a script via netbackup to kill jobs running after a certain time.  I don't want the script to kill all jobs, though, just specific jobs/policies.

 

I'm not strong on the scripting, but here's what I'm running:

bpdbjobs -cancel type=backup

 

I don't see how I can use this script to kill a specific policy when needed.

 

My master server is a windows 2003 box running 6.5GA

discussion Filed Under:

Comments

Darren Dunham's picture
24
Oct
2008
0 Votes 0
Login to vote

Use the outpout of 'bpdbjobs' (which includes running status and policy name) to create a list of jobs that you want to kill.  So if it's not the policy you're interested in, you leave it off the list.

 

Then feed that list of jobs to bpdbjobs -cancel.

 

--

Darren

sdw303's picture
25
Oct
2008
1 Vote +1
Login to vote

A quick swim in the river of VB...

 

This is unsupported.  Use at your own risk.  I won't amend it.  It's a base for you to continue with.  I'm not a teacher, and I won't be holding classes in VBScript or programming for that matter.

 

 

Anyway, it's in two parts:

1) DOS that can easily be run from a scheduled task.

2) VBScript to parse the activity list and determine which jobs to cancel, and cancel them.

 

 

@echo offsetlocal enabledelayedexpansionset z_path=%~dp0set z_name=%~n0set z_act=!z_path!!z_name!.actset z_log=!z_path!!z_name!.logset z_tmp=!z_path!!z_name!.tmpif exist "!z_act!" del "!z_act!"if exist "!z_log!" del "!z_log!"if exist "!z_tmp!" del "!z_tmp!"bpdbjobs -most_columns -file "!z_act!"cscript //nologo backup-cancel.vbs:endexit /b:logecho !time:~0,8! %%1echo !time:~0,8! %%1 >> "!z_log!"goto :eof

 

 

Option Explicit'Global constants...Const ci_for_reading= 1Const ci_for_writing= 2Const ci_for_appending= 8Const cs_bs= "\"'Global vars...Dim go_fso, go_wshDim gs_script_spec, gs_script_path, gs_script_name'Main routines...Call s_init()Call s_main()WScript.Quit(0)Sub s_init() Const cs_fac = "%s_init, " Set go_fso = CreateObject( "Scripting.FileSystemObject") Set go_wsh = CreateObject( "WScript.Shell") gs_script_spec = Wscript.ScriptFullName gs_script_path = go_fso.GetParentFolderName( gs_script_spec ) gs_script_name = go_fso.GetBaseName( gs_script_spec )End SubSub s_main() Const cs_fac = "%s_main, " Dim ls_file, lo_chan, ls_rec, ll_recs ls_file = gs_script_path & cs_bs & gs_script_name & ".act" Set lo_chan = go_fso.OpenTextFile( ls_file, ci_for_reading ) ll_recs = 0 Do ls_rec = lo_chan.ReadLine ll_recs = ll_recs + 1 Call s_process( ls_rec ) Loop Until lo_chan.AtEndOfStream lo_chan.Close Call s_log( cs_fac & "Read `" & ll_recs & "` records from `" & ls_file & "`..." )End SubSub s_process( ps_rec ) Const cs_fac = "%s_process," Dim ls_fields, lb_cancel Dim ls_act_jobid, ls_act_type, ls_act_state, ls_act_status, ls_act_policy, ls_act_schedule Dim ls_act_client, ls_act_media, ls_act_queued, ls_act_duration, ls_act_end Dim ls_act_stu, ls_act_try, ls_act_kb, ls_act_files, ls_act_path, ls_act_percentage, ls_act_pid, ls_act_owner Dim ls_act_sub_type, ls_act_policy_type, ls_act_schedule_type, ls_act_priority, ls_act_group, ls_act_master Dim ls_act_retention_u, ls_act_retention_p, ls_act_parent, ls_act_kbs, ls_act_copy, ls_act_stream, ls_act_image_id Dim ls_act_28, ls_act_29, ls_act_30, ls_act_31, ls_act_32 ls_fields = Split( ps_rec, "," ) ls_act_jobid= ls_fields( 0 ) ls_act_type= ls_fields( 1 ) If ls_act_type <> "0" Then Exit Sub'Only backups get through... ls_act_state= ls_fields( 2 ) If ls_act_state = "3" Then Exit Sub'If job is completed... ls_act_status= ls_fields( 3 ) ls_act_policy= ls_fields( 4 ) ls_act_schedule= ls_fields( 5 ) ls_act_client= ls_fields( 6 ) ls_act_media= ls_fields( 7 ) ls_act_queued= ls_fields( 8 ) ls_act_duration= ls_fields( 9 ) ls_act_end= ls_fields( 10 ) ls_act_stu= ls_fields( 11 ) ls_act_try= ls_fields( 12 ) ls_act_kb= ls_fields( 14 ) ls_act_files= ls_fields( 15 ) ls_act_path= ls_fields( 16 ) ls_act_percentage= ls_fields( 17 ) ls_act_pid= ls_fields( 18 ) ls_act_owner= ls_fields( 19 ) ls_act_sub_type= ls_fields( 20 ) ls_act_policy_type= ls_fields( 21 ) ls_act_schedule_type= ls_fields( 22 ) ls_act_priority= ls_fields( 23 ) ls_act_group= ls_fields( 24 ) ls_act_master= ls_fields( 25 ) ls_act_retention_u= ls_fields( 26 ) ls_act_retention_p= ls_fields( 27 ) ls_act_28= ls_fields( 28 ) ls_act_29= ls_fields( 29 ) ls_act_30= ls_fields( 30 ) ls_act_31= ls_fields( 31 ) ls_act_32= ls_fields( 32 ) ls_act_parent= ls_fields( 33 ) ls_act_copy= ls_fields( 35 ) ls_act_stream= ls_fields( 45 ) ls_act_image_id= ls_fields( 51 ) lb_cancel = False If UCase( ls_act_policy ) = "TEST3"Then lb_cancel = True' If UCase( ls_act_client ) = "MY.CLIENT.FQDN.COM"Then lb_cancel = True If lb_cancel Then Call s_log( cs_fac & "Cancelling job id `" & ls_act_jobid & "`..." ) Call s_cancel( ls_act_jobid ) End IfEnd SubSub s_cancel( ps_jobid ) Const cs_fac = "%s_cancel, " Dim ll_status, ls_command, ls_log_file ls_command = "bpdbjobs -cancel " & ps_jobid ls_log_file = gs_script_path & cs_bs & gs_script_name & ".log" ll_status = go_wsh.Run( "%comspec% /c " & ls_command & " >> """ & ls_log_file & """", 0, True ) Select Case Err.Number Case 0 Case Else Call s_log( cs_fac & "Attempt to cancel job `" & ps_jobid & "` failed, error `" & Err.Number & "`..." ) Exit Sub End Select Select Case ll_status Case 0 Case Else Call s_log( cs_fac & "Attempt to cancel job `" & ps_jobid & "` failed, status `" & ll_status & "`..." ) Exit Sub End SelectEnd SubSub s_log( ls_message ) WScript.Echo ls_messageEnd Sub

 

sdw303's picture
28
Oct
2008
0 Votes 0
Login to vote

One that got away?

sdw303's picture
01
Nov
2008
0 Votes 0
Login to vote

Alex, I actually took time out to write this for you.

 

A response would be appreciated.  Rubbish?  Useful?