jmtrevaskis

writecachemonitor.kix

Aug 16th, 2012
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. ; reboot on logoff if the writecache is full
  2. ; by james trevaskis
  3. ; 26/07/2012
  4. ; version 0.03
  5.  
  6.  
  7. ;vars
  8.  
  9. ;target write cache in mb - currently 750mb
  10. $writecachet = 750
  11.  
  12. ;write cache drive letter
  13. $writecached = d:\
  14.  
  15. ;debug
  16. $debug=1
  17. $serverlogpath="\\network.local\citrix_writecachemonitor.log"
  18.  
  19.  
  20.  
  21. ;main
  22.  
  23. ;get current free space
  24. $freespaceraw=diskspace($writecached, 1)
  25.  
  26. ;convert freespace to int
  27. $freespacearray = split($freespaceraw, ".")
  28. $freespace = $freespacearray[0]
  29.  
  30. ;debug
  31. if ($debug)
  32. ? " "
  33. ? "debug mode"
  34. ? " "
  35. ? " target freespace - " $writecachet
  36. ? "current freespace - " $freespace
  37. ? " "
  38. endif
  39.  
  40. ;evaluate freespace
  41. if ($writecachet > $freespace)
  42. $debugOutput = "Write cache size is currently $freespace, less than the desired value, rebooting..."
  43. debugOut($debugOutput)
  44. shutdown("", "System is being rebooted to flush write cache", 10, 1, 1)
  45. else
  46. $debugOutput = "Write cache size is currently $freespace, within acceptable limits..."
  47. debugOut($debugOutput)
  48. endif
  49.  
  50.  
  51.  
  52. :EOF
  53. exit
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60. ;functions
  61.  
  62.  
  63. ;debug output
  64. function debugOut($command)
  65. if ($debug)
  66. ? $command
  67. shell '%comspec% /c echo @DATE @TIME : Citrix Logoff Event : User @USERID , workstation @WKSTA - $command >>$ServerLogPath'
  68. endif
  69. endfunction
  70.  
  71.  
  72. ;thanks to Jens Meyer for the diskspace function
  73. function diskspace(optional $drive, optional $format)
  74. dim $objWMIService, $sWQL, $colDrives, $objDrive
  75. if not $drive
  76. $drive='%WINDIR%'
  77. endif
  78. $format=val($format)
  79. if $format<5
  80. $format=iif($format=1,1024,iif($format=2,1024.0*1024,iif($format=3,1024.0*1024*1024,iif($format=4,1024.0*1024*1024*1024,1))))
  81. $diskspace=cdbl(GETDISKSPACE($drive))/$format
  82. else
  83. $objWMIService=getobject('winmgmts:{impersonationLevel=impersonate}!\\'+@WKSTA+'\root\cimv2')
  84. $sWQL = "SELECT Size, FreeSpace FROM Win32_LogicalDisk WHERE Name='"+left($drive,2)+"'"
  85. $colDrives=$objWMIService.ExecQuery($sWQL)
  86. for each $objDrive in $colDrives
  87. $diskspace=cdbl($objDrive.FreeSpace)/cdbl($objDrive.Size)*100
  88. next
  89. endif
  90. exit @ERROR
  91. endfunction
Add Comment
Please, Sign In to add comment