Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for srvspace.bat

(view source code of srvspace.bat as plain text)

  1. @ECHO OFF
  2. ECHO.>CON
  3. ECHO SrvSpace.cmd,  version 1.12 for Windows NT>CON
  4. ECHO Display free disk space per server>CON
  5. ECHO Output is TAB delimited for redirection purposes>CON
  6. ECHO.>CON
  7. ECHO Written by Rob van der Woude>CON
  8. ECHO http://www.robvanderwoude.com>CON
  9. ECHO.>CON
  10.  
  11. :: Check for new servers
  12. FOR /F "skip=3 eol=T tokens=1* delims=\ " %%A IN ('NET VIEW') DO CALL :AddServer %%A
  13. :: Check all servers from server list
  14. FOR /F "tokens=*" %%A IN ('TYPE %~dpn0.srv ^| SORT') DO CALL :Server %%A
  15. GOTO:EOF
  16.  
  17.  
  18. :AddServer
  19. :: Check if the server list exists, add server if not
  20. IF NOT EXIST %~dpn0.srv GOTO :Add
  21. :: Check if server is already in server list, add server if not
  22. TYPE %~dpn0.srv | FIND /I "%1" >NUL
  23. IF NOT ERRORLEVEL 1 GOTO:EOF
  24. :Add
  25. (ECHO.%1)>>%~dpn0.srv
  26. GOTO:EOF
  27.  
  28.  
  29. :Server
  30. :: Check drives C: through F: on each server
  31. FOR %%a IN (C D E F) DO CALL :DiskFree %1 %%a
  32. GOTO:EOF
  33.  
  34.  
  35. :DiskFree
  36. :: Check if this drive exists on this server
  37. DIR \\%1\%2$ >NUL 2>NUL
  38. IF ERRORLEVEL 1 GOTO:EOF
  39. SETLOCAL
  40. :: Map network drive
  41. FOR /F "eol=T tokens=2* delims= " %%? in ('NET USE * \\%1\%2$ 2^>NUL') DO SET drive=%%?
  42. :: Check amount of free bytes
  43. FOR /F "tokens=1* delims= " %%? IN ('DIR /A %drive% 2^>NUL ^| FIND "bytes free"') DO SET bytes=%%?
  44. :: Display amount of free bytes
  45. ECHO \\%1\%2$	%bytes%	bytes free
  46. :: Disconnect network drive
  47. NET USE %drive% /D >NUL 2>NUL
  48. ENDLOCAL
  49. GOTO:EOF
  50.  

page last modified: 2024-04-16; loaded in 0.0091 seconds