我需要监控服务是否已达到容量的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!
)
)
端部
暂停
假设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%