Pavan DBA's Blog

The DBA Knowledge Store

Posts Tagged ‘Script to check disk space on Windows’

Script to check disk space on Windows

Posted by Pavan DBA on March 9, 2012


######################################

DISK SPACE CHECK ON WINDOWS

######################################

usageLog = “C:\UsageLog.txt”

 

‘ 5%

 

 

Const cdoSendUsingMethod = “http://schemas.microsoft.com/cdo/configuration/sendusing”

Const cdoSendUsingPort = 2

Const cdoSMTPServer = “http://schemas.microsoft.com/cdo/configuration/smtpserver”

Const cdoSMTPServerPort = “http://schemas.microsoft.com/cdo/configuration/smtpserverport”

Const cdoSMTPConnectionTimeout = “http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout”

Const cdoSMTPAuthenticate = “http://schemas.microsoft.com/cdo/configuration/smtpauthenticate”

Const cdoBasic = 1

Const cdoSendUserName = “http://schemas.microsoft.com/cdo/configuration/sendusername”

Const cdoSendPassword = “http://schemas.microsoft.com/cdo/configuration/sendpassword”

 

 

Dim objEmail

 

‘ WScript.Echo “Hi”

 

 

”””””””””””””””

‘ Mail for I Drive

”””””””””””””””’

minCapacity = 0.03

Set fso = WScript.CreateObject(“Scripting.FileSystemObject”)

Set oDrive = fso.GetDrive(“I”)

curSpace = oDrive.FreeSpace

totSize = oDrive.TotalSize

 

curUsage = curSpace/totSize

curFree = 1 – curUsage

 

‘WScript.Echo “Current free space: ” & FormatNumber(oDrive.FreeSpace,0)

‘WScript.Echo “Total size: ” & FormatNumber(oDrive.TotalSize,0)

‘WScript.Echo “Current usage(%): ” & FormatPercent(curUsage, 2)

‘WScript.Echo “Current free(%): ” & FormatPercent(curFree, 2)

 

‘————————-

‘ Check the capacity here

‘————————-

if curUsage < minCapacity then

‘ WScript.Echo “Too low!”

 

‘ write log file here

‘ Set fso = CreateObject(“Scripting.FileSystemObject”)

‘ Set f = fso.CreateTextFile(usageLog, True)

‘ f.WriteLine(“Space too low!”)

‘ f.Close

 

‘—————————-

‘Mailing Starts Here

‘—————————-

 

Set objEmail = CreateObject (“CDO.Message”)

Set Conf = CreateObject(“CDO.Configuration”)

 

Conf.Fields.Item(cdoSendUsingMethod) = cdoSendUsingPort

‘ Conf.Fields.Item(cdoSMTPServer) = “BP1XEUEX707-C.bp1.ad.bp.com”

Conf.Fields.Item(cdoSMTPServer) = “amsmtp.bp.com”

 

Conf.Fields.Item(cdoSMTPServerPort) = 25

Conf.Fields.update

set objEmail.Configuration = conf

 

objEmail.To = “dba_ora_offshore@bp.com; 919949520316@airtelap.com”

objEmail.From = “dba_ora_offshore@bp.com”

objEmail.Subject = “Disk Space Alert on I Drive for bp1tulap151(prd2)”

objEmail.HTMLBody = round(curSpace/1024/1024/1024,2) & “GB free space is available on I Drive – bp1tulap151(prd2)”

objEmail.Send

 

‘ wscript.echo “Mail Sent”

Set objEmail = nothing

Set Conf = nothing

 

‘——————————

‘Mailing ends here

‘—————————–

 

else

‘ WScript.Echo “OK!”

end if

 

 

Posted in Administration, Scripts | Tagged: , , , , | Leave a Comment »

 
%d bloggers like this: