Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

This I am missing the last server on my list 1

Status
Not open for further replies.

Pyro777

MIS
Jul 14, 2006
47
US
This script goes out and checks all of the servers that I add to a text file called servers.txt on my C:\ drive. The script works great with one issue. If I have 3 servers listed. It will display all 3 servers, total disk space, used disk space and available disk space with no issues. At the end of the totals, it displays the total Used disk space and total disk capacity for all of the servers on my servers.txt list. Here is the issue. In the grand totals, it drops off the last servers drive space listed on my list.
EX:
Server Name Total Size Free Space %Free Used Space
Server1 194.4 GB 77 GB 40% 117.4 GB
Server2 31.2 GB 13 GB 42% 18.2 GB
Server3 52 GB 31.7 GB 61% 20.3 GB

*Total Used Disk Space is 135.6
*Total Disk Space is 225.6

The script has not added the totals for Server3. The script seems to drop off the last server listed in the Servers.txt file... Here is the code..

On Error Resume Next
'**********************
'* Standard Variables *
'**********************

strserverlist = "C:\serverlist.txt"


'**********************
'* Constant Variables *
'**********************
Const ForReading=1, ForWriting=2, ForAppending=8
Dim strserverlist, objshell, fso, webfullreport, strSendAppEmail, strSendHostingEmail, usedtotal, total, mydatetime, report
Set objShell = CreateObject("Wscript.Shell")
MyDateTime = Month(Date) & "-" & Right ("0" & Day(Date), 2) & "-" & Right("0" & Year(Date), 2)
Dim driveletter(24)
report="fulldiskreport"
Set fso = CreateObject("Scripting.FileSystemObject")
Set webfullreport = fso.createTextFile("C:\"& report &"-" & myDateTime & ".xls")
strSendAppEmail = "false"
strSendHostingEmail = "false"
initDrives
addtop

'**********************
'* Setup HTML Table *
'**********************

WebFullReport.WriteLine ("<table border=1>")
WebFullReport.WriteLine ("<tr>")
WebFullReport.WriteLine ("<td><b>Server Name </b></td>")
WebFullReport.WriteLine ("<td><b>Total Size</b></td>")
WebFullReport.WriteLine ("<td><b>Free Space</b></td>")
WebFullReport.WriteLine ("<td><b>% Free</b></td>")
WebFullReport.WriteLine ("<td><b>Used Space</b></td>")
WebFullReport.WriteLine ("</tr>")


'**********************
'* Scan Servers *
'**********************

Set SERVERS = fso_OpenTextFile(strserverlist, 1)
Do While SERVERS.AtEndOfStream <> True
server = SERVERS.Readline
Set objScriptExec = objShell.Exec("ping -n 1 -w 1000 " & server)
strPingResults = LCase(objScriptExec.StdOut.ReadAll)
If InStr(strPingResults, "reply from") Then

usedtotal = usedtotal + serverusedtotal
total = total + servertotalsize
servertotalsize = 0
serverusedtotal = 0
serveravailsize = 0
for I=1 To 24
if fso.DriveExists(fso.GetDriveName(fso.GetAbsolutePathName("\\" & server & "\" & driveletter(I) & "$"))) then
Set drive = fso.Getdrive(fso.GetDriveName(fso.GetAbsolutePathName("\\" & server & "\" & driveletter(I) & "$")))
totalsize = FormatNumber(drive.TotalSize/1024/1024/1024, 1)
availsize = FormatNumber(drive.AvailableSpace/1024/1024/1024, 1)
percentfree = FormatNumber((availsize/totalsize)*100, 0)
serverusedtotal = serverusedtotal + (totalsize - availsize)
servertotalsize = servertotalsize + totalsize
serveravailsize = serveravailsize + availsize

end If
Next
' These Give you your end totals - Phil !!!!
WebFullReport.WriteLine ("<tr bgcolor=silver><td align=right><b>" & server & "</b></td>")
WebFullReport.WriteLine ("<td><b>" & servertotalsize & " GB</b></td>")
WebFullReport.WriteLine ("<td><b>" & serveravailsize & " GB</b></td>")
WebFullReport.WriteLine ("<td><b>" & FormatNumber((serveravailsize/servertotalsize)*100,0) & "%</b></td>")
WebFullReport.WriteLine ("<td><b>" & FormatNumber(serverusedtotal, 1) & " GB</b></td></tr>")
end If
Loop

'**********************
'* Format Report *
'**********************


WebFullReport.WriteLine ("</table>")
WebFullReport.WriteLine ("<Br><Br><h3>*Total Used Disk Space is " & usedtotal & "</h3>")
WebFullReport.WriteLine ("<h3>*Total Disk Space is " & total & "</h3>")
AppCriticalReport.WriteLine ("</table>")
HostingCriticalReport.WriteLine ("</table>")


addbottom


sub addtop
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'' Create Top of WebFullReport Page
WebFullReport.WriteLine ("<html><head><title>CCMC Server Storage Stats</title></head><body>")
WebFullReport.WriteLine ("<td><b>CCMC Server Storage Stats as of " & date & " at " & time & "</b></td>")

end Sub




sub addbottom
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'' Add Bottom of Web Page
WebFullReport.WriteLine ("</div>")
WebFullReport.WriteLine ("<!----FOOTER BEGINS HERE---->")
WebFullReport.WriteLine ("<hr>")
WebFullReport.WriteLine ("<!--OISWEB:Do Not Modify or Delete This Line-->")
WebFullReport.WriteLine ("</body>")
WebFullReport.WriteLine ("</html>")

end Sub

sub initDrives
driveletter(1) = "C"
driveletter(2) = "D"
driveletter(3) = "E"
driveletter(4) = "F"
driveletter(5) = "G"
driveletter(6) = "H"
driveletter(7) = "I"
driveletter(8) = "J"
driveletter(9) = "K"
driveletter(10) = "L"
driveletter(11) = "M"
driveletter(12) = "N"
driveletter(13) = "O"
driveletter(14) = "P"
driveletter(15) = "Q"
driveletter(16) = "R"
driveletter(17) = "S"
driveletter(18) = "T"
driveletter(19) = "U"
driveletter(20) = "V"
driveletter(21) = "W"
driveletter(22) = "X"
driveletter(23) = "Y"
driveletter(24) = "Z"
end Sub

WebFullReport.close



 
Move the 2 following lines:
usedtotal = usedtotal + serverusedtotal
total = total + servertotalsize
just after this line:
' These Give you your end totals - Phil !!!!

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV,
I knew it was something minor, but I am learning as I go along... You totally ROCK, Works Great Now !!! I just gave you a star....

Thanks for all of your help... In case anyone else wants this code here is the final working code... Thanks to PHV !!

On Error Resume Next
'**********************
'* Standard Variables *
'**********************

strserverlist = "C:\serverlist.txt"


'**********************
'* Constant Variables *
'**********************
Const ForReading=1, ForWriting=2, ForAppending=8
Dim strserverlist, objshell, fso, webfullreport, strSendAppEmail, strSendHostingEmail, usedtotal, total, mydatetime, report
Set objShell = CreateObject("Wscript.Shell")
MyDateTime = Month(Date) & "-" & Right ("0" & Day(Date), 2) & "-" & Right("0" & Year(Date), 2)
Dim driveletter(24)
report="fulldiskreport"
Set fso = CreateObject("Scripting.FileSystemObject")
Set webfullreport = fso.createTextFile("C:\"& report &"-" & myDateTime & ".xls")
strSendAppEmail = "false"
strSendHostingEmail = "false"
initDrives
addtop

'**********************
'* Setup HTML Table *
'**********************

WebFullReport.WriteLine ("<table border=1>")
WebFullReport.WriteLine ("<tr>")
WebFullReport.WriteLine ("<td><b>Server Name </b></td>")
WebFullReport.WriteLine ("<td><b>Total Size</b></td>")
WebFullReport.WriteLine ("<td><b>Free Space</b></td>")
WebFullReport.WriteLine ("<td><b>% Free</b></td>")
WebFullReport.WriteLine ("<td><b>Used Space</b></td>")
WebFullReport.WriteLine ("</tr>")


'**********************
'* Scan Servers *
'**********************

Set SERVERS = fso_OpenTextFile(strserverlist, 1)
Do While SERVERS.AtEndOfStream <> True
server = SERVERS.Readline
Set objScriptExec = objShell.Exec("ping -n 1 -w 1000 " & server)
strPingResults = LCase(objScriptExec.StdOut.ReadAll)
If InStr(strPingResults, "reply from") Then

' usedtotal = usedtotal + serverusedtotal
' total = total + servertotalsize
servertotalsize = 0
serverusedtotal = 0
serveravailsize = 0
for I=1 To 24
if fso.DriveExists(fso.GetDriveName(fso.GetAbsolutePathName("\\" & server & "\" & driveletter(I) & "$"))) then
Set drive = fso.Getdrive(fso.GetDriveName(fso.GetAbsolutePathName("\\" & server & "\" & driveletter(I) & "$")))
totalsize = FormatNumber(drive.TotalSize/1024/1024/1024, 1)
availsize = FormatNumber(drive.AvailableSpace/1024/1024/1024, 1)
percentfree = FormatNumber((availsize/totalsize)*100, 0)
serverusedtotal = serverusedtotal + (totalsize - availsize)
servertotalsize = servertotalsize + totalsize
serveravailsize = serveravailsize + availsize

end If
Next
' These Give you your end totals - Phil !!!!
usedtotal = usedtotal + serverusedtotal
total = total + servertotalsize
WebFullReport.WriteLine ("<tr bgcolor=silver><td align=right><b>" & server & "</b></td>")
WebFullReport.WriteLine ("<td><b>" & servertotalsize & " GB</b></td>")
WebFullReport.WriteLine ("<td><b>" & serveravailsize & " GB</b></td>")
WebFullReport.WriteLine ("<td><b>" & FormatNumber((serveravailsize/servertotalsize)*100,0) & "%</b></td>")
WebFullReport.WriteLine ("<td><b>" & FormatNumber(serverusedtotal, 1) & " GB</b></td></tr>")
end If
Loop

'**********************
'* Format Report *
'**********************


WebFullReport.WriteLine ("</table>")
WebFullReport.WriteLine ("<Br><Br><h3>*Total Used Disk Space is " & usedtotal & "</h3>")
WebFullReport.WriteLine ("<h3>*Total Disk Space is " & total & "</h3>")
AppCriticalReport.WriteLine ("</table>")
HostingCriticalReport.WriteLine ("</table>")


addbottom


sub addtop
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'' Create Top of WebFullReport Page
WebFullReport.WriteLine ("<html><head><title>CCMC Server Storage Stats</title></head><body>")
WebFullReport.WriteLine ("<td><b>CCMC Server Storage Stats as of " & date & " at " & time & "</b></td>")

end Sub




sub addbottom
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'' Add Bottom of Web Page
WebFullReport.WriteLine ("</div>")
WebFullReport.WriteLine ("<!----FOOTER BEGINS HERE---->")
WebFullReport.WriteLine ("<hr>")
WebFullReport.WriteLine ("<!--OISWEB:Do Not Modify or Delete This Line-->")
WebFullReport.WriteLine ("</body>")
WebFullReport.WriteLine ("</html>")

end Sub

sub initDrives
driveletter(1) = "C"
driveletter(2) = "D"
driveletter(3) = "E"
driveletter(4) = "F"
driveletter(5) = "G"
driveletter(6) = "H"
driveletter(7) = "I"
driveletter(8) = "J"
driveletter(9) = "K"
driveletter(10) = "L"
driveletter(11) = "M"
driveletter(12) = "N"
driveletter(13) = "O"
driveletter(14) = "P"
driveletter(15) = "Q"
driveletter(16) = "R"
driveletter(17) = "S"
driveletter(18) = "T"
driveletter(19) = "U"
driveletter(20) = "V"
driveletter(21) = "W"
driveletter(22) = "X"
driveletter(23) = "Y"
driveletter(24) = "Z"
end Sub

WebFullReport.close
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top