SQL Server 任务监控脚本

BEGIN

 
DECLARE @jobstatus

TABLE(Job_ID uniqueidentifier, Last_Run_Date int, Last_Run_Time int, Next_Run_Date int,

    Next_Run_Time int,Next_Run_Schedule_ID int, Requested_To_Run int,

    Request_Source int, Request_Source_ID varchar(100),

Running int, Current_Step int, Current_Retry_Attempt int, State int)

INSERT INTO @jobstatus

EXEC MASTER.dbo.xp_sqlagent_enum_jobs 1,garbage
 
                BEGIN

                SELECT DISTINCT CASE
                   WHEN state=1 THEN 'Job is Executing'
                   WHEN state=2 THEN 'Waiting for thread to complete'
                   WHEN state=3 THEN 'Between retries'
                   WHEN state=4 THEN 'Job is Idle'
                   WHEN state=5 THEN 'Job is suspended'
                   WHEN state=7 THEN 'Performing completion actions'
 
                END AS State,sj.name,

                CASE WHEN ej.running=1 THEN st.step_id ELSE 0 END AS currentstepid,
                CASE WHEN ej.running=1 THEN st.step_name ELSE 'not executing' END AS currentstepname,

                st.command, ej.request_source_id

                FROM @jobstatus ej join msdb..sysjobs sj ON sj.job_id=ej.job_id

                JOIN msdb..sysjobsteps st ON st.job_id=ej.job_id AND (st.step_id=ej.current_step or ej.current_step=0)

                WHERE ej.running+1>1

                END

END


转载于:https://my.oschina.net/sunyh/blog/40927

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值