批处理脚本监控系统

时间:2015-07-06 08:54:21

标签: file batch-file

我需要监控服务是否已达到容量的80%-90%,它会发出警告。而我似乎无法使它成功。

REM dir c:\|find /i "bytes free" >> CDrive.txt


 for /f %%c in (C.txt) do (


set %%c=104847433728


if %%c LSS 127578980352 (

      echo Drive is not yet full.


) elseif %%c GEQ 127578980352 (

       if %%c LSS 143526352896

           echo Send WARNING!

       if %%c LEQ 159473725441 

            echo Send CRITICAL!

)

)

ENDLOCAL

PAUSE

1 个答案:

答案 0 :(得分:0)

假设dir /-c C:\ |findstr "bytes.free"的输出如下:

   18 Dir(s)    997019979776 bytes free
   -- ------    ------------
   ^  ^         ^ 3rd token
   ^  ^ 2nd token
   ^ 1st token

然后下一个代码片段可以工作,虽然我的逻辑中有一些不清楚的地方(即%%c GTR 159473725441案例):

@ECHO OFF
SETLOCAL enableextensions
for /f "tokens=3" %%c in ('dir /-c C:\ ^|findstr "bytes.free"') do (
   set "_sizeC=%%c"
   if %%c LSS 127578980352 (
      echo Drive is not yet full.
   ) else (
       if %%c LSS 143526352896 (
          echo Send WARNING!
       ) else if %%c LEQ 159473725441 echo Send CRITICAL! 
   )
)
echo _sizeC=%_sizeC%