screwuphead Posted November 20, 2007 Posted November 20, 2007 I know i could always buy a program to do this but wheres the fun in that? so I need a program that will go through a list of servers and then a list of their drives and check to see how much free space is left on those drives, from their if it is anything less then 30GB i need it to send an email to me. i am using psexec to access these remote servers and run cmd. then to email myself i am using postie. the problem i am having is wrapping that all up in a if-then-else command that will look for the specified free space. It doesnt work right now beacuse for whatever reason it is bring back a true statement when the statement is false because i know the server its checking is more then 30GB free. This is what i have so far: @echo off for /f %%S IN (serverPClist.txt) DO ( echo Checking drives on Server %%S... for /D %%D IN (C D F G H I J K X V E) DO ( psexec \\%%S cmd /c if exist %%D:\* dir %%D:\ | findstr /c:"bytes" > %temp%\%%S-%%D.txt ) ) color 0D for /f %%S IN (serverPClist.txt) DO ( echo. & echo. echo ********** Displaying output for server %%S... ********** for /D %%D IN (C D E F G I J K) DO ( for /f "tokens=1,2,3,4" %%F IN ('if exist %temp%\%%S-%%D.txt type %temp%\%%S-%%D.txt') DO ( if /i "%%G" == "Dir(s)" echo For the %%D: drive: %%H bytes free space. if /i "%%G" == "bytes" echo For the %%D: drive: %%F bytes free space. echo. ) ) echo Done! ) echo Generating HTML... REM this part of the script generates an HTML file with all the relevant information REM and then launches it using the default browser. set FileName="C:\Report.html" echo ^ > %FileName% echo ^ >> %FileName% echo ^Free Space on NRCE Servers^ >> %FileName% echo ^ >> %FileName% echo ^ >> %FileName% echo ^^Free Hard Drive Space Report^^^ >> %FileName% for /f %%S IN (serverPClist.txt) DO ( REM mark the server echo ^^%%S^^^ >> %FileName% for /D %%D IN (C D E F G I J K) DO ( for /f "tokens=1,2,3,4" %%F IN ('if exist %temp%\%%S-%%D.txt type %temp%\%%S-%%D.txt') DO ( REM add a line for the drive and free space if /i "%%G" == "Dir(s)" echo ^Free space on ^%%D:^ drive: ^^ COLOR=GREEN^>%%H^^ bytes free^^ >> %FileName% if /i "%%G" == "bytes" echo ^Free space on ^%%D:^ drive: ^^ COLOR=GREEN^>%%F^^ bytes free^^ >> %FileName% ) ) REM mark some spacing lines into the HTML file echo ^ >> %FileName% ) echo ^ >> %FileName% echo ^ >> %FileName% REM launch the HTML file set positive=1 set amount="30,000,000,000" if %%f leq %amount% set violation=1 if %%h leq %amount% set violation=1 echo %violation% if %violation% equ %positive% postie -host:(SMTP SERVER) -to:(MY EMAIL) -from:(NETWORK EMAIL) -s:"Server Report" -msg:"THERE IS A VIOLATION!" -a:"C:\ServerReports\Report.html" echo Done! If anybody else has anything better plz show me, otherwise i will keep playing around with this coding.
screwuphead Posted November 20, 2007 Author Posted November 20, 2007 maybe i should of mentioned that this is going on a windows machine
ICT_GUY Posted November 20, 2007 Posted November 20, 2007 Server 2003 hacks has a script to do this, but then again spiceworks does this and makes it look pretty!
mattx Posted November 21, 2007 Posted November 21, 2007 You could use AutoIT's DriveSpaceFree function: $var = DriveSpaceFree( "c:\" ) MsgBox(4096, "Free space on C:", $var & " MB")
greenfieldsupport Posted November 21, 2007 Posted November 21, 2007 your missing a chevron: set FileName="C:\Report.html" echo ^ > %FileName% <<<<<< echo ^ >> %FileName% echo ^Free Space on NRCE Servers^ >> %FileName% If that helps at all? and and ensure you have something near the start that sets violation to 0, otherwise you will have to manually reset it every time... even if there is now enough space... and this line msg:"THERE IS A VIOLATION!" -a:"C:\ServerReports\Report.html" should read msg:"THERE IS A VIOLATION!" -a:%FileName% or at least msg:"THERE IS A VIOLATION!" -a:"C:\Report.html"
screwuphead Posted November 26, 2007 Author Posted November 26, 2007 is there any security risks with spiceworks since its free? does it phone home at all?
sahmeepee Posted November 26, 2007 Posted November 26, 2007 This has been done with bells on here: http://www.vbshf.com/vbshf/forum/forums/thread-view.asp?tid=8 (as a vbscript) Trying to build HTML with windows batch files is evil! Too many ^s! 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now