獲取作業執行的資訊

2021-05-25 16:35:36 字數 4188 閱讀 8988

if object_id('dbo.spgetjobinfo') is not null

drop procedure dbo.spgetjobinfo

gocreate procedure dbo.spgetjobinfo

asset nocount on

declare @jobid varchar(50)

declare @sql nvarchar(1000)

create table #jobs_schedule(

[schedule_id] [int],

[name] [sysname],

[enabled] [int],

[freq_type] [int],

[freq_interval] [int],

[freq_subday_type] [int],

[freq_subday_interval] [int],

[freq_relative_interval] [int],

[freq_recurrence_factor] [int],

[active_start_date] [int],

[active_end_date] [int],

[active_start_time] [int],

[active_end_time] [int],

[date_created] [datetime],

[desc] varchar(1000),

[next_run_date] [int],

[next_run_time] [int],

[schedule_uid]    varchar(1000),

[job_count] [int]

) on [primary]

declare c1 cursor for select job_id from msdb..sysjobs

open c1

fetch next from c1 into @jobid

while @@fetch_status=0

begin

insert #jobs_schedule exec ('msdb..sp_help_jobschedule @job_id='''+ @jobid+''',@include_description=1')

fetch next from c1 into @jobid

endclose c1

deallocate c1

create table #tempjoin

(job_id uniqueidentifier,

jobs varchar(250),

category varchar(250),

ownername  varchar(100),

schedulename  varchar(250),

isenabled  char(4),

frequency varchar(250),

date_created  datetime,

active_start_date int,

next_run_date  int,

next_run_time int

)insert into #tempjoin

(job_id,

jobs,

category,

ownername,

schedulename,

isenabled,

frequency,

date_created,

active_start_date,

next_run_date,

next_run_time)(

select

a.[job_id],

a.[jobs],

a.[category],

l.[name] as [owner],

a.[schedule name],

a.[enabled],

temp.[desc] as [frequecy],

temp.date_created as [datecreated],

temp.active_start_date as [startdate],

temp.next_run_date as [nextrundate],

temp.next_run_time as [nextruntime]

from #jobs_schedule as temp

right outer join

(select

j.job_id,

j.[name] as [jobs],

j.owner_sid,

c.[name] as [category],

js.schedule_id,

s.[name] as [schedule name],

case j.enabled when 1 then 'yes' else 'no' end as [enabled]

from msdb..syscategories as c

right outer join

msdb..sysjobs as j on c.category_id = j.category_id

left outer join

msdb..sysjobschedules as js on j.job_id = js.job_id

left outer join

msdb..sysschedules as s on js.schedule_id = s.schedule_id)

as a on temp.schedule_id = a.schedule_id

left outer join

sys.server_principals as l on a.owner_sid = l.sid)

create table #tempjoin1

(name varchar(250),

job_id uniqueidentifier,

lastrunstatus varchar(25),

lastrundate int,

lastruntime int,

)insert into #tempjoin1

(name,

job_id,

lastrunstatus,

lastrundate,

lastruntime)(

select 

j.[name] as [jobname],

j.[job_id], 

run_status = case h.run_status 

when 0 then 'failed'

when 1 then 'succeeded'

when 2 then 'retry'

when 3 then 'canceled'

when 4 then 'in progress'

end,

h.run_date as lastrundate,  

h.run_time as lastruntime

from msdb..sysjobhistory h 

inner join

msdb..sysjobs j on h.job_id = j.job_id 

where h.instance_id in 

(select max(h.instance_id) 

from msdb..sysjobhistory h group by (h.job_id))

)select

t1.jobs,

t1.ownername,

t1.category,

t1.date_created,

t1.active_start_date,

t1.isenabled,

t2.lastrundate,

t2.lastruntime,

t2.lastrunstatus

from #tempjoin t1

inner join #tempjoin1 t2

on t1.job_id = t2.job_id

drop table #jobs_schedule

drop table #tempjoin

drop table #tempjoin1

go

獲取系統執行程序資訊 PSAPI介紹使用

網上資料顯示,有這麼三種方法可以用來獲取系統執行程序資訊 方法平台 備註psapi windows nt,windows2000,windows xp 獲取程序,驅動器,模組,記憶體和工作集資訊 效能計數器 windows nt,windows2000,windows xp 提供除程序清單以外的關於...

資訊收集 網域名稱資訊獲取

二 收集網域名稱資訊 三 收集子網域名稱 四 ip位址收集 五 開發埠收集 網域名稱 domain name 又稱網域,是由一串用點分隔的名字組成的internet上某一台計算機或計算機組的名稱,用於在資料傳輸時對計算機的定位標識。當我們訪問乙個 時,我們既可以通過它的網域名稱進行訪問,也可以通過直...

獲取網絡卡資訊

在windows中獲取網路介面卡相關資訊是很方便的,可以通過getadaptersinfo函式獲取並儲存在ip adapter info結構體中,再對結構休進行解析得到介面卡資訊。有關函式和結構體的詳細說明可以參考msdn,這裡就不再複述。下面直接給出具體示例程式。引入標頭檔案 include in...