SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


disk space Report by email


disk space Report by email

Author
Message
c.ajitkumar
c.ajitkumar
Old Hand
Old Hand (357 reputation)Old Hand (357 reputation)Old Hand (357 reputation)Old Hand (357 reputation)Old Hand (357 reputation)Old Hand (357 reputation)Old Hand (357 reputation)Old Hand (357 reputation)

Group: General Forum Members
Points: 357 Visits: 666
Hi All,

Can any one post a script that will send disk space details in a HTML format by a email in SQL server 2005.


Thanks in advance.


Ajit
Lowell
Lowell
One Orange Chip
One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)

Group: General Forum Members
Points: 27938 Visits: 39921
if you have the query, we can help you html-ize it.

what have you put together so far?

Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

durai nagarajan
durai nagarajan
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1603 Visits: 2775
SET NOCOUNT ON
DECLARE @hr int
DECLARE @fso int
DECLARE @drive char(1)
DECLARE @odrive int
DECLARE @TotalSize varchar(20) DECLARE @MB Numeric ; SET @MB = 1048576
CREATE TABLE #drives (drive char(1) PRIMARY KEY, FreeSpace int NULL, TotalSize int NULL)

INSERT #drives(drive,FreeSpace)
EXEC master.dbo.xp_fixeddrives

EXEC @hr=sp_OACreate 'Scripting.FileSystemObject',@fso OUT

IF @hr <> 0
EXEC sp_OAGetErrorInfo @fso

DECLARE dcur CURSOR LOCAL FAST_FORWARD
FOR SELECT drive from #drives ORDER by drive
OPEN dcur FETCH NEXT FROM dcur INTO @drive
WHILE @@FETCH_STATUS=0
BEGIN
EXEC @hr = sp_OAMethod @fso,'GetDrive', @odrive OUT, @drive
IF @hr <> 0
EXEC sp_OAGetErrorInfo @fso EXEC @hr = sp_OAGetProperty @odrive,'TotalSize', @TotalSize OUT
IF @hr <> 0 EXEC sp_OAGetErrorInfo @odrive
UPDATE #drives
SET TotalSize=@TotalSize/@MB
WHERE drive=@drive FETCH NEXT FROM dcur INTO @drive
End
Close dcur
DEALLOCATE dcur
EXEC @hr=sp_OADestroy @fso
IF @hr <> 0
EXEC sp_OAGetErrorInfo @fso

DECLARE @tableHTML NVARCHAR(MAX)
DECLARE @subject1 NVARCHAR(110)

SET @tableHTML = '<p>Hello All,</p> <p>The drive free space details.</p>'+
'<table border="1" cellspacing="0" cellpadding="0" >' +
'<tr align="center"><td><strong>Server Name</strong></td><td><strong>Date</strong></td>' +
'<td><strong>Drive</strong></td>'+
'<td><strong>Total(GB)</strong></td><td><strong>Free(GB)</strong></td>' +
'<td><strong>Free Space (in %)</strong></td>'+
'</tr><TR align="center">' +
CAST ( ( SELECT td = @@servername, '',
td = convert(varchar,getdate(),106), '',
td = Drive, '',
td = convert(decimal(7,2),TotalSize/1024.0), '',
td = convert(decimal(7,2),FreeSpace/1024.0), '',
td = convert(decimal(7,2),(convert(decimal(7,2),FreeSpace/1024.0)/(TotalSize/1024.0))*100), ''
from #drives
--where convert(decimal(7,2),(convert(decimal(7,2),FreeSpace/1024.0)/(TotalSize/1024.0))*100) < 25.00
FOR XML PATH('TR'), TYPE
) AS NVARCHAR(MAX) ) +
N'</tr></table>'

select @subject1 = @@servername + ' Drive space Details'

if @tableHTML is not NULL and @subject1 is not null
begin
EXEC msdb.dbo.sp_send_dbmail
@body_format='HTML',
@body=@tableHTML,
@recipients=N'EMail id ',
@subject = @subject1,@profile_name ='Profile'

End


DROP TABLE #drives

SET NOCOUNT OFF

this is what i use, change it according to your requirement.

Regards
Durai Nagarajan
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search