Login | |
|
 |
VBScript to check diskspace; threshold & Database shrin... - 5/7/2008 11:43:27 PM
|
|
 |
|
| |
marconi
Posts: 8
Score: 0
Joined: 5/7/2008
Status: offline
|
I have 3 jobservers and a database server. 1) I need to first check the disk space.2) then check if the free space on each drive is greater than 15% of the total disk space(which is the threshold value) and notify the user.3) then shrink the databases. I have written the following VBSCript, but it is not serving the purpose. Request you to please provide me with the correct inputs/script. -------------------------------------------------------------------------------------Set iFSO = CreateObject("Scripting.FilesyStemObject") Set oFSO = CreateObject("Scripting.FilesyStemObject") InputFile="Diskspace.txt" Outputfile="Diskspacelist.csv" Set ofile = ofso.createTextFile(OutputFile) Set ifile = ifSO.OpenTextFile(inputfile) Const GBCONVERSION= 1048576000 ofile.writeline "Server,Drive,Disk Size,FreeSpace" Do until ifile.AtEndOfLine Server = ifile.ReadLine Set objWMIService = GetObject("winmgmts://" & Server) Set colLogicalDisk = objWMIService.InstancesOf("Win32_LogicalDisk") For Each objLogicalDisk In colLogicalDisk if objLogicalDisk.drivetype=3 then ofile.writeline Server & "," & objLogicalDisk.DeviceID &_ "," & FormatNumber(objLogicalDisk.size/GBCONVERSION,2) & "GB, " &_ FormatNumber(objLogicalDisk.freespace/GBCONVERSION,2) & "GB, " end if Next Loop iThreshold=(15/100)*(size) iSize=freespaceIf Int(iSize) < Int(iThreshold) Then 'free space is less than the threshold so generate an alert wscript.Echo "Alert!" strDescription=objLogicalDisk.freespace & " is less than the specified threshold of " &_ FormatNumber(iThreshold,2,,True) & " GB. Free space is " &_ FormatNumber(iSize,2,,True) & " GB" wscript.echo strDescription Else 'folder size is OK WScript.Echo "The size of " &freespace & " (" & iSize &_ ") is at least the threshold of " & iThreshold End If------------------------------------------------------------------------------------------- Thanks a lot in advance. Marconi.
|
|
| |
|
|
|
 |
RE: VBScript to check diskspace; threshold & Database s... - 5/8/2008 12:25:47 AM
|
|
 |
|
| |
ebgreen
Posts: 4408
Score: 29
Joined: 7/12/2005
Status: offline
|
What error do you get. What line does it error on? While I could read through this line by line pretending I am a script interpreter, you have a perfectly good interpreter that is currently telling you exactly what the problem is. Please share this information.
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: VBScript to check diskspace; threshold & Database s... - 5/8/2008 2:34:24 AM
|
|
 |
|
| |
ebgreen
Posts: 4408
Score: 29
Joined: 7/12/2005
Status: offline
|
Ok, so read through what you have written and understand what it does. For instance, you loop through all the server names then after that you do the comparison. So at best you would only be doing the comparison for the very last drive of the very last server. If you want to do something for every server, it must be in the loop where you are doing things for every server, not outside the loop. Also, look at this line: iThreshold=(15/100)*(size) Where do you ever populate the size variable?
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: VBScript to check diskspace; threshold & Database s... - 5/8/2008 2:59:14 AM
|
|
 |
|
| |
ebgreen
Posts: 4408
Score: 29
Joined: 7/12/2005
Status: offline
|
I will happily help you with pseudo code that you can look at to help with the logic for the real code: Open a file that lists all the servers to check For each server For each disk on the server check the free space to see if it is less than the limit Next Next Right now you do the checking part completely outside the loop.
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: VBScript to check diskspace; threshold & Database s... - 5/8/2008 3:30:06 AM
|
|
 |
|
| |
marconi
Posts: 8
Score: 0
Joined: 5/7/2008
Status: offline
|
Hi, Yes thats true, the script should be something like this :- ----------------------------------------------------------------------------------------------------------------------------------------------- Set iFSO = CreateObject("Scripting.FilesyStemObject") Set oFSO = CreateObject("Scripting.FilesyStemObject") InputFile="Diskspace.txt" Outputfile="Diskspacelist.csv" Set ofile = ofso.createTextFile(OutputFile) Set ifile = ifSO.OpenTextFile(inputfile) Const GBCONVERSION= 1048576000 ofile.writeline "Server,Drive,Disk Size,FreeSpace" Do until ifile.AtEndOfLine Server = ifile.ReadLine Set objWMIService = GetObject("winmgmts://" & Server) Set colLogicalDisk = objWMIService.InstancesOf("Win32_LogicalDisk") For Each objLogicalDisk In colLogicalDisk if objLogicalDisk.drivetype=3 then ofile.writeline Server & "," & objLogicalDisk.DeviceID &_ "," & FormatNumber(objLogicalDisk.size/GBCONVERSION,2) & "GB, " &_ FormatNumber(objLogicalDisk.freespace/GBCONVERSION,2) & "GB, " end if iThreshold=(15/100)*(Disksize) If Int(freespace) < Int(iThreshold) Then 'freespace is less than the threshold so generate an alert wscript.Echo "Alert!" strDescription=freespace & " is less than the specified threshold of " &_ FormatNumber(iThreshold,2,,True) & " GB. Free space is " &_ FormatNumber(iSize,2,,True) & " GB" wscript.echo strDescription Else 'folder size is OK WScript.Echo "The size of freespace is at least the threshold of " & iThreshold End If Next Loop ------------------------------------------------------------------------------------------------------------------------------------------------------ But my query is that, I am getting Junk values due to improper code for calculating the threshold which is 15% of the actual size. I am calculating as :- iThreshold=(15/100)*(size) which is not correct. Request you to please help me with the proper script for this. Thanks in advance. Regards, Marconi.
|
|
| |
|
|
|
 |
RE: VBScript to check diskspace; threshold & Database s... - 5/8/2008 5:13:47 AM
|
|
 |
|
| |
Country73
Posts: 709
Score: 8
Joined: 8/25/2004
From: USA
Status: offline
|
This code has not been tested, but hopefully I was able to read you code well enough to interpret. Set iFSO = CreateObject("Scripting.FileSystemObject") 'Delete / do not need Set oFSO = CreateObject("Scripting.FileSystemObject") InputFile="Diskspace.txt" Outputfile="Diskspacelist.csv" SET ofile = oFSO.CreateTextFile(OutputFile) SET ifile = oFSO.CreateTextFile(inputfile) Const GBCONVERSION= 1048576000 ofile.writeline "Server,Drive,Disk Size,FreeSpace" DO UNTIL ifile.AtEndOfLine Server = ifile.ReadLine SET objWMIService = GetObject("winmgmts://" & Server) SET colLogicalDisk = objWMIService.InstancesOf("Win32_LogicalDisk") FOR EACH objLogicalDisk In colLogicalDisk IF objLogicalDisk.drivetype=3 then 'Set variables to make it easier to read 'Set Disksize variable for size so you can use later Disksize = FormatNumber(objLogicalDisk.size/GBCONVERSION,2) & "GB" Freespace = FormatNumber(objLogicalDisk.freespace/GBCONVERSION,2) & "GB" DeviceID = objLogicalDisk.DeviceID 'Write to file using the variables ofile.writeline Server & "," & DeviceID & "," & Disksize & "," & Freespace END IF 'Disksize was set in last IF statement iThreshold=(15/100)*(Disksize) IF INT(freespace) < INT(iThreshold) THEN 'freespace is less than the threshold so generate an alert wscript.Echo "Alert!" 'Set variables to help read code better iThresh = FormatNumber(iThreshold,2,,TRUE) & " GB" iFreespace = FormatNumber(freespace,2,,TRUE) & " GB" strDescription = freespace & " is less than the specified threshold of " &_ iThresh & ". Free space is " & iFreespace wscript.echo strDescription ELSE 'folder size is OK WScript.Echo "The size of freespace is at least the threshold of " & iThreshold END IF Next SET colLogicalDisk = NOTHING SET objWMIService = NOTHING LOOP
|
|
| |
|
|
|
| |
|
|
 |
|
 |
|
|