+ Post New Thread
Results 1 to 9 of 9
Scripts Thread, Script Need to check disk space on remote servers in Coding and Web Development; I know i could always buy a program to do this but wheres the fun in that? so I need ...
  1. #1

    Join Date
    Nov 2007
    Location
    Chicago, IL
    Posts
    8
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Script Need to check disk space on remote servers

    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 -hostSMTP SERVER) -toMY EMAIL) -fromNETWORK 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.

  2. #2


    Join Date
    Jan 2006
    Posts
    8,202
    Thank Post
    442
    Thanked 1,032 Times in 812 Posts
    Rep Power
    339

    Re: Script Need to check disk space on remote servers

    enable snmp and install nagios

  3. #3

    Join Date
    Nov 2007
    Location
    Chicago, IL
    Posts
    8
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Re: Script Need to check disk space on remote servers

    maybe i should of mentioned that this is going on a windows machine

  4. #4
    ICT_GUY's Avatar
    Join Date
    Feb 2007
    Location
    Weymouth
    Posts
    2,261
    Thank Post
    646
    Thanked 283 Times in 204 Posts
    Rep Power
    104

    Re: Script Need to check disk space on remote servers

    Server 2003 hacks has a script to do this, but then again spiceworks does this and makes it look pretty!

  5. #5

    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    11,803
    Thank Post
    110
    Thanked 583 Times in 504 Posts
    Blog Entries
    1
    Rep Power
    224

    Re: Script Need to check disk space on remote servers

    You can check this via SNMP or WMI.

  6. #6

    mattx's Avatar
    Join Date
    Jan 2007
    Posts
    9,240
    Thank Post
    1,058
    Thanked 1,068 Times in 625 Posts
    Rep Power
    740

    Re: Script Need to check disk space on remote servers

    You could use AutoIT's DriveSpaceFree function:

    Code:
    $var = DriveSpaceFree( "c:\" )
    MsgBox(4096, "Free space on C:", $var & " MB")

  7. #7
    greenfieldsupport's Avatar
    Join Date
    Mar 2007
    Location
    Newton Aycliffe, Durham
    Posts
    240
    Thank Post
    14
    Thanked 3 Times in 3 Posts
    Rep Power
    16

    Re: Script Need to check disk space on remote servers

    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?
    :P

    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"

  8. #8

    Join Date
    Nov 2007
    Location
    Chicago, IL
    Posts
    8
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Re: Script Need to check disk space on remote servers

    is there any security risks with spiceworks since its free?
    does it phone home at all?

  9. #9
    sahmeepee's Avatar
    Join Date
    Oct 2005
    Location
    Greater Manchester
    Posts
    795
    Thank Post
    20
    Thanked 70 Times in 42 Posts
    Rep Power
    33

    Re: Script Need to check disk space on remote servers

    This has been done with bells on here:

    http://www.vbshf.com/vbshf/forum/for...view.asp?tid=8

    (as a vbscript)

    Trying to build HTML with windows batch files is evil! Too many ^s!

  10. Thanks to sahmeepee from:

    kennysarmy (23rd September 2008)

SHARE:

Similar Threads

  1. How much disk space do you have for SIMS.net?
    By indiegirl in forum MIS Systems
    Replies: 91
    Last Post: 12th November 2007, 02:10 PM
  2. Help my server thinks its run out of disk space.
    By pickman in forum Wireless Networks
    Replies: 7
    Last Post: 12th October 2007, 09:45 AM
  3. Server 2003 strange disk space issue.
    By starscream in forum Windows
    Replies: 12
    Last Post: 3rd August 2007, 12:07 AM
  4. server disk space
    By david12345 in forum Hardware
    Replies: 8
    Last Post: 24th July 2007, 04:28 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •