本帖最后由 zds612 于 2018-11-1 09:26 编辑
回复 11# Batcher
感谢大大的帮忙,对我很有帮助,已经可以正常计算了
但是出现另一个问题,不管警戒值设为多大,结果都是空间充裕
问题1:感觉好像我那个比较的if语句没有什么作用,能劳烦帮我看看嘛?
问题2:批处理中带小数的数字如何取整?- @echo off
- mode con cols=50 lines=10
- color 0a
- Title -[磁盘检测程序(自动电邮告警)]
- set log_file_name=RunLog.txt
- set lineno_max=365
- set avail=100000
- set svrname="测试服务器"
- set ipaddr="132.147.180.000"
- set freesize=0
- set num=1048576
- set disk1=c
-
- if NOT exist %log_file_name% (echo 执行日志:>%log_file_name%)
- for /f "delims=:" %%a in ('findstr/n .* "%log_file_name%"') do set lineno=%%a
- echo %log_file_name%文件共有%lineno%行
- if %lineno% GTR %lineno_max% (echo 执行日志:>%log_file_name% && echo %log_file_name%文件已经清空!)
-
- for /f "tokens=3 delims= " %%a in ('dir /-c %disk1%:') do set "mc=%%a"
- echo %mc%字节
-
-
- set suru=%mc%/%num%
- call :cu0 %suru:/= % freesize
-
- echo %disk1%盘剩余空间为%freesize%MB
- echo 警戒值为%avail%MB
- if %freesize% LSS %avail% (goto xiaoyu) else (goto exit)
- :xiaoyu
- echo %disk1%盘空间不足%avail%MB,将电邮告警!
- echo 发电邮告警....(此功能由CmdMail实现,此处仅作演示说明。)
- ping -n 4 127.1>nul
- pause&&exit
-
- :exit
- echo 空间充裕,程序退出。&& echo %date% %time%:执行本程序,%disk1%盘磁盘空间%freesize%MB,未达到警戒值%avail%MB;>>%log_file_name%
- ping -n 4 127.1>nul
- pause&&exit
-
-
- :cu0 500位内整数除法函数(封装)by @随风 bbs.bathome.net
- ::函数内有 cu1 cu2 cu3 cu4 四个标签,引用时需注意
- setlocal enabledelayedexpansion&set "lin=00000"
- set /a zongw=1000,cs1w=0,cs2w=0,falg=0,x=0
- if "!str!"=="1" Endlocal&set %~3=%ff%!num!&goto :EOF
- if "%~1"=="0" set sang=0&goto cu4
- if "!str!"=="0" set sang=以零为除数的错误。&goto cu4
- if not defined xiaosu set /a xiaosu=10
- for /l %%a in (1 1 5) do set "lin=!lin!!lin!!lin!"
- set sang=&set ppp=&set var1=%~1&set "var2=%~2"
- for /f "tokens=* delims=0" %%a in ("!var1!")do set var1=%%a
- for /f "tokens=* delims=0" %%a in ("!var2!")do set var2=%%a
- for /l %%a in (0 1 9)do (set "var1=!var1:%%a= %%a !"
- set "var2=!var2:%%a= %%a !")
- for %%a in (!var1!) do set /a cs1w+=1
- for %%a in (!var2!) do set /a cs2w+=1
- for /l %%a in (1 1 10) do (set t=&set cs=%~2&set/a j=0
- for /l %%b in (1 1 !cs2w!) do (set /a a=%%a*!cs:~-1!+j
- set t=!a:~-1!!t!&set a=0!a!&set "j=!a:~-2,1!"
- set cs=!cs:~0,-1!&set cs%%a=&set "bj%%a=")
- if !j! neq 0 (set cs%%a=!lin!!j!!t!&set "bj%%a=!j!!t!"
- ) else set cs%%a=!lin!!t!&set "bj%%a=!t!"
- set "cs%%a=!cs%%a:~-%zongw%!")
- set var2=!lin!!var2: =!&set "var2=!var2:~-%zongw%!"
- set /a cswc=cs1w-cs2w&set "var1=!var1: =!"
- if !cswc! lss 0 (set cswc=!cswc:-=!&set/a flag=1
- for /l %%a in (1 1 !cswc!)do (
- if %%a leq 11 set sang=0!sang!&set /a x=cswc-1
- set "var1=!var1!0")
- set "sang=!sang:~0,1!.!sang:~1!")
- set ppp=!var1:~0,%cs2w%!&set "var1=!var1:~%cs2w%!"
- if !flag! equ 1 (set /a bul=1) else set /a bul=0
- goto cu2
- :cu1
- if not defined var1 (set "var1=0"
- if not defined ppp goto cu4
- if !flag! equ 0 (set sang=!sang!.&set /a flag=1))
- set/a bul=1&set ppp=!ppp!!var1:~0,1!&set "var1=!var1:~1!"
- :cu2
- if !x! geq %xiaosu% goto cu4
- set pvar1=!lin!!ppp!&set "pvar1=!pvar1:~-%zongw%!"
- if "!pvar1!" lss "!var2!" (
- if !bul! equ 1 (set sang=!sang!0&set /a bul=0
- if !flag! equ 1 set /a x+=1)
- if "!ppp:~0,1!"=="0" set "ppp="
- goto cu1)
- if !flag! equ 1 set /a x+=1
- set /a bul=0
- ::计算商
- for /l %%a in (1 1 10) do (
- if "!cs%%a!" equ "!pvar1!" (
- set "sang=!sang!%%a"&set "yu=!bj%%a!"&goto cu3)
- if "!cs%%a!" gtr "!pvar1!" (set /a s=%%a-1
- set "sang=!sang!!s!"&set yu=!t!&goto cu3)
- set "t=!bj%%a!")
- :cu3 计算差
- set cjs=!ppp!&set cj1=&set m=&set/a jjj=0
- for /l %%a in (0 1 9) do set "cjs=!cjs:%%a= %%a !"
- for %%a in (!cjs!) do set "cj1=%%a !cj1!"
- for %%a in (!cj1!) do (if "!yu!"=="" set/a yu=0
- set /a a=%%a-jjj,b=!yu:~-1!
- if !a! lss !b! (set /a a+=10,jjj=1)else set/a jjj=0
- set /a w=a-b&set m=!w!!m!&set yu=!yu:~0,-1!)
- for /f "tokens=* delims=0" %%m in ("!m!") do (
- if "%%m"=="" (set m=0) else set "m=%%m")
- if !m! equ 0 (
- if "!var1:0=!"=="" set sang=!sang!!var1!&goto cu4
- set ppp=&goto cu1) else set "ppp=!m!"
- goto cu2
- :cu4
- if "!sang:~0,1!"=="." set "sang=0!sang!"
- Endlocal&set %~3=%ff%%sang%&goto :EOF
复制代码
|