#52590 - 2000-12-06 01:42 PM
GetDiskSpace Only Works The 2nd Time?
|
Anonymous
Anonymous
Unregistered
|
Hi Gang,I have a minor problem, I have created a script that checks how much free space that is available on all our servers, but the first time i run the script (with administrative rights) all the results are 1.99 GB, then i run it again, and the second time i run it, it returns the right amount. I have included a little OLE command inspired by the grear minds of Shawn and Bryce, at the forum  Here goes:
code:
Setconsole ("HIDE")$cd = olecreateobject("MSComDlg.CommonDialog") $rs = oleputproperty ( $cd, "Filter", "s", "Text Files(*.txt)|*.txt|All Files(*.*)|*.*" ) $rs = oleputproperty ( $cd, "FilterIndex", "s", "1") $rs = oleputproperty ( $cd, "MaxFileSize", "s", "256") $rs = oleputproperty ( $cd, "DialogTitle", "s", "Save the results...") $rs = oleputproperty ( $cd, "Flags", "s", "&H10006") $rs = olecallfunc ( $cd, "ShowOpen" ) $FileName = olegetproperty ( $cd, "FileName") $rs = olereleaseobject ( $cd) Open (1, "$FileName", 5) Writeline (1, Chr(013) + Chr (010)) Writeline (1, "Check Started @Date @Time" + Chr(013) + Chr(010)) $Space = GetDiskSpace("\\server1\c$") $Server = "Server1" $Drive = "C" Gosub "Calculate" Gosub "WriteToFile" $Space = GetDiskSpace("\\server1\d$") $Server = "Server1" $Drive = "D" Gosub "Calculate" Gosub "WriteToFile" $Space = GetDiskSpace("\\server2\c$") $Server = "Server2" $Drive = "C" Gosub "Calculate" Gosub "WriteToFile" $Space = GetDiskSpace("\\server2\d$") $Server = "Server2" $Drive = "D" Gosub "Calculate" Gosub "WriteToFile" $Space = GetDiskSpace("\\server3\c$") $Server = "Server3" $Drive = "C" Gosub "Calculate" Gosub "WriteToFile" $Space = GetDiskSpace("\\server3\d$") $Server = "Server3" $Drive = "D" Gosub "Calculate" Gosub "WriteToFile" $Space = GetDiskSpace("\\server4\c$") $Server = "Server4" $Drive = "C" Gosub "Calculate" Gosub "WriteToFile" $Space = GetDiskSpace("\\server5\c$") $Server = "Server5" $Drive = "C" Gosub "Calculate" Gosub "WriteToFile" $Space = GetDiskSpace("\\server5\d$") $Server = "Server5" $Drive = "D" Gosub "Calculate" Gosub "WriteToFile" Goto "End" :WriteToFile $X = Writeline (1, "Free Space On $Server $Drive Drive: " + "$ErrMsg" + Chr(013) + Chr(010)) Return :Calculate Select Case $Space < 1024 ;** Kilobytes $Space = $Space * 100 $Units = " Kilobytes" Case $Space => 1024 and $Space < 1048576 ;** Megabytes $Space = ($Space * 100) / 1024 $Units = " Megabytes" Case $Space => 1048576 ;** Gigabytes $Space = $Space / 10486 $Units = " Gigabytes" ENDSELECT ;** Convert the $Space value to a string by adding a space to the beginning $Space = " " + $Space $Length = LEN($Space) ;** Add the decimal point 2 spaces from the end. $Space = SUBSTR($Space, 1, $Length - 2) + "." + SUBSTR($Space,$Length - 1, 2) $ErrMsg = LTRIM($Space) + $Units Return
:End Close (1)
The OLE thing is mostly just for fun, but I think it is a really cool feature, and the routine could be implemented into loads of other scripts. A thing that I would like to implement is the abilty to insert the collected data into an Excel Worksheet, and update a graph. If anyone can help please post, it would be really appreciated 
------------------ Cheers.... David
|
|
Top
|
|
|
|
#52591 - 2000-12-06 02:44 PM
Re: GetDiskSpace Only Works The 2nd Time?
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
David:Good work ! But I have to report that I ran your script over here and ... "It works like a charm !"  Anyone else !?!?!? Shawn. p.s. David is using OLE and the common dialogs to query for the report name... You may or may not have this ActiveX component installed on your workstation ! Check it out !
|
|
Top
|
|
|
|
#52592 - 2000-12-06 03:34 PM
Re: GetDiskSpace Only Works The 2nd Time?
|
Anonymous
Anonymous
Unregistered
|
Hallas, Great script, the only thing I might suggest is to put the server names into a different file so adding servers will be easy.This is a script I wrote a while back, it outputs drive space to the screen and warns when the space is too low. I just had it run in my login script. It reads in file with server names and drives to check. DriveSpace.kix
code:
$ServerNames="C:\WINNT\Profiles\mpearce\Desktop\scripts\servers.txt" $LowSpace = 600 GOSUB "DrawBack" $XLine = 2 $YLine = 2IF Open(3, "$ServerNames",2) = 0 $ScanLine = ReadLine(3) WHILE @ERROR = 0 ;? "Line read: [" + $x + "]" $CommaPosition=INSTR($ScanLine,",") $ServerName=SUBSTR($ScanLine,1,$CommaPosition -1) $ScanLine=SUBSTR($ScanLine,$CommaPosition+1,LEN($ScanLine)) WHILE $CommaPosition <> 0 $CommaPosition=INSTR($ScanLine,",") IF $CommaPosition = 0 $ServerDrive=$ScanLine ELSE $ServerDrive=SUBSTR($ScanLine,1,$CommaPosition -1) ENDIF GOSUB "ShowDriveInfo" $ScanLine=SUBSTR($ScanLine,$CommaPosition+1,LEN($ScanLine)) LOOP $ScanLine = ReadLine(3) GOSUB "PlusY" LOOP $x = Close (3) ELSE BEEP ? "Config file not opened, error code: [" + @ERROR + "]" Get $x ENDIF goto "end" :ShowDriveInfo
$diskspace=GetDiskSpace( "\\$ServerName\$ServerDrive$$" ) $dsmb = $diskspace /1024 IF $dsmb < 300 Color +r/b ENDIF AT ($YLine,$XLine) "\\$ServerName\$ServerDrive$$" $dsmb = " $dsmb" $dsmb = SUBSTR($dsmb, LEN($dsmb) - 4, 5) AT ($YLine,$XLine + 20) "$dsmb MB" GOSUB "PlusY" Color +y/b return :drawback small CLS color b+/b BOX (0,0,23,79,SINGLE) color y+/b AT (0,47) " " + @DAY + ", " + @MONTH + " " + @MDAYNO + " " + @YEAR + " " return :PlusY $YLine = $YLine + 1 IF $YLine = 20 IF $XLine = 42 GOSUB "PlusX" ELSE $XLine = 42 $YLine = 2 ENDIF ENDIF return :PlusX Color +g/b AT (23,25) "(Press any key to continue)" Color +y/b get $x GOSUB "Drawback" $XLine = 2 $YLine = 2 return :end GOSUB "PlusX"
Server.txt
code:
SERVER1,C,D,E SERVER2,C,D SERVER3,C,D,E SERVER4,C,D,E SERVER5,C,D,E SERVER6,C,D,E SERVER7,C,D SERVER8,C,D SERVER9,C SERVER10,C,D,E SERVER11,C,D,E,F,G
Mark P.
|
|
Top
|
|
|
|
#52593 - 2000-12-08 09:52 AM
Re: GetDiskSpace Only Works The 2nd Time?
|
Anonymous
Anonymous
Unregistered
|
Thanks for the positive feedback, thats really appreciated. Does anyone known about something that could interfeer with my script so I would not get the right results? You know like a program, setting or anything?And Mark thanks for the script, great idea, I will begin implementing it right away. But I would like to take the results and put them in an Excel Worksheet, is there anybody out there that knows how to do that? It could also be cool to put them in a Database, but I dont know how to do that either  And Shawn, did you get my mail regarding the VB 5.0 Program using ADSI? ------------------ Cheers.... David
|
|
Top
|
|
|
|
#52594 - 2000-12-08 10:06 AM
Re: GetDiskSpace Only Works The 2nd Time?
|
Anonymous
Anonymous
Unregistered
|
Guys,I think I figured out. When I run the script on my Win ME machine it only works the second time, but when I run it directly on a server (with the Kix RPC service installed) it works the first time.....what a coincidence...he he That properbly rings a bell in a lot of peoples minds  But im still interested in implemting some more OLE to the script  ------------------ Cheers.... David
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 484 anonymous users online.
|
|
|