SQL Server 任务监控脚本
来源:未知 责任编辑:智问网络 发表时间:2013-10-30 11:12 点击:次
BEGIN
02
03
04
DECLARE @jobstatus
05
06
TABLE(Job_ID uniqueidentifier, Last_Run_Date int, Last_Run_Time int, Next_Run_Date int,
07
08
Next_Run_Time int,Next_Run_Schedule_ID int, Requested_To_Run int,
09
10
Request_Source int, Request_Source_ID varchar(100),
11
12
Running int, Current_Step int, Current_Retry_Attempt int, State int)
13
14
INSERT INTO @jobstatus
15
16
EXEC MASTER.dbo.xp_sqlagent_enum_jobs 1,garbage
17
18
BEGIN
19
20
SELECT DISTINCT CASE
21
WHEN state=1 THEN 'Job is Executing'
22
WHEN state=2 THEN 'Waiting for thread to complete'
23
WHEN state=3 THEN 'Between retries'
24
WHEN state=4 THEN 'Job is Idle'
25
WHEN state=5 THEN 'Job is suspended'
26
WHEN state=7 THEN 'Performing completion actions'
27
28
END AS State,sj.name,
29
30
CASE WHEN ej.running=1 THEN st.step_id ELSE 0 END AS currentstepid,
31
CASE WHEN ej.running=1 THEN st.step_name ELSE 'not executing' END AS currentstepname,
32
33
st.command, ej.request_source_id
34
35
FROM @jobstatus ej join msdb..sysjobs sj ON sj.job_id=ej.job_id
36
37
JOIN msdb..sysjobsteps st ON st.job_id=ej.job_id AND (st.step_id=ej.current_step or ej.current_step=0)
38
39
WHERE ej.running+1>1
40
41
END
42
43
END
摘自 sunyh的博客
02
03
04
DECLARE @jobstatus
05
06
TABLE(Job_ID uniqueidentifier, Last_Run_Date int, Last_Run_Time int, Next_Run_Date int,
07
08
Next_Run_Time int,Next_Run_Schedule_ID int, Requested_To_Run int,
09
10
Request_Source int, Request_Source_ID varchar(100),
11
12
Running int, Current_Step int, Current_Retry_Attempt int, State int)
13
14
INSERT INTO @jobstatus
15
16
EXEC MASTER.dbo.xp_sqlagent_enum_jobs 1,garbage
17
18
BEGIN
19
20
SELECT DISTINCT CASE
21
WHEN state=1 THEN 'Job is Executing'
22
WHEN state=2 THEN 'Waiting for thread to complete'
23
WHEN state=3 THEN 'Between retries'
24
WHEN state=4 THEN 'Job is Idle'
25
WHEN state=5 THEN 'Job is suspended'
26
WHEN state=7 THEN 'Performing completion actions'
27
28
END AS State,sj.name,
29
30
CASE WHEN ej.running=1 THEN st.step_id ELSE 0 END AS currentstepid,
31
CASE WHEN ej.running=1 THEN st.step_name ELSE 'not executing' END AS currentstepname,
32
33
st.command, ej.request_source_id
34
35
FROM @jobstatus ej join msdb..sysjobs sj ON sj.job_id=ej.job_id
36
37
JOIN msdb..sysjobsteps st ON st.job_id=ej.job_id AND (st.step_id=ej.current_step or ej.current_step=0)
38
39
WHERE ej.running+1>1
40
41
END
42
43
END
摘自 sunyh的博客
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>