查看trace文件信息

if exists(select * from sysobjects where xtype='P' and name='up_dircmd')
drop procedure up_dircmd
go

CREATE procedure dbo.up_dircmd
@pathfile nvarchar(256),
@mark nvarchar(256)='' --默认匹配全部

AS
/**********
--文件名 :
--用途 :查看trace文件信息
--输入参数 :
--返回值解释 :
--创建者 : summer.yang
--创建日期 : 2005-6-18
--修改者 :
--修改日期 :
--修改注解 :(引用请保留此信息)
--备注说明 :也可以用于查看某个路径下的其他文件信息
**********/
set @pathfile=ltrim(rtrim(@pathfile))
-------
declare @return int
set @return=0
-------
create table #tbl(
rowid int not null identity,
cmd_output nvarchar(1000) null ,
path_file nvarchar(256) null default '',
write_time smalldatetime null )

declare @cmd nvarchar(1000)
set @cmd='dir '+@pathfile
insert into #tbl(cmd_output)
exec master.dbo.xp_cmdshell @cmd
set @return=@@error
if @return<>0
begin
raiserror 50000 'The stored procedure executed failed.'
goto finish
end

update #tbl
set cmd_output=' '
where cmd_output is null
update #tbl
set write_time=case when substring(cmd_output,18,1)='p' then
dateadd(hh,12,convert(smalldatetime,substring(cmd_output,1,17),120) )
else convert(smalldatetime,substring(cmd_output,1,17),120) end,
path_file=substring(cmd_output,len(cmd_output)-charindex(' ',reverse(cmd_output),1)+2,charindex(' ',reverse(cmd_output),1))
where isdate(substring(cmd_output,1,17))=1

if right(@pathfile,1)<>''
begin
if exists(select * from #tbl where path_file=right(@pathfile,charindex('',reverse(@pathfile),1)-1))
set @pathfile=substring(@pathfile,1,len(@pathfile)-charindex('',reverse(@pathfile),1)+1)
else
set @pathfile=@pathfile+''
end

update #tbl
set path_file=@pathfile+path_file
where write_time is not null

if @mark <>'' and @mark is not null
begin
select * from #tbl where cmd_output like '%'+@mark+'%'
end
else
begin
select * from #tbl
end

finish:
---------

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值