create proc usp_sendspacealert
as
--此存储需要打开xp_cmdshell执行权限
--定义磁盘剩余空间表
declare @y table (DRIVE varchar(2),FREE_MB INT)
insert into @y exec master.dbo.xp_fixeddrives
--定义磁盘总空间临时信息表
--此步骤通过dos命令diskpart调用输入结果存入临时表中,需要在C:\目录中存在a.txt文件,且a.txt文件内容为"list vol"
declare @x table (volinfo varchar(200))
insert into @x exec xp_cmdshell 'diskpart < c:\a.txt |findstr "Partition" '
delete from @x where volinfo is NULL
--定义磁盘空间表
declare @z table (DRIVENAME varchar(2),DISKSPACE_GB INT)
insert INTo @z
select substring (volinfo,charindex('volume',volinfo,0)+13,1) AS DRIVENAME,
substring (volinfo,charindex('partition',volinfo,0)+9,
charindex ('GB',volinfo,0)-charindex ('partition',volinfo,0)-9)AS DISKSPACE_GB from @x
--判断是否有剩余空间小于20%的磁盘,如果存储就将结果集以HTML格式发出
if exists
(select a.DRIVE,a.FREE_MB/1024 as FREE_GB,b.DISKSPAC