批处理脚本以检查文件的大小并发送邮件(如果更大) [英] batch script to check the size of file and send mail if greater

查看:100
本文介绍了批处理脚本以检查文件的大小并发送邮件(如果更大)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究批处理脚本,该脚本检查文件的大小并在大小大于0字节的情况下发送电子邮件:

I have been working on a batch script which checks for the size of a file and send an email in case the size is greater than 0 byte:

set V_TMP_FILE="D:\pmserver\Tgtfiles\XLI_stage\f_cdc_flag1.out" 
set minbytesize=0  
if exist %V_TMP_FILE% (
FOR %%A IN ('%V_TMP_FILE%') DO set size=%%~zA
if %size% GTR %minbytesize% (
    %V_EMAIL_PATH%\postie -host:internalmail.usa.xl -to:"%V_TO_EMAIL_ID%" -from:%COMPUTERNAME%@xlgroup.com -s:"%V_SRC_TABLE_NM% %V_SUBJ%" -msg:"%V_MSG%" 
) else (
    echo %V_TMP_FILE% is EMPTY
)


我收到以下错误-


I am getting the below error -

标准输出和错误:

h file. 0 was unexpected at this time.

D:\Informatica91\server\bin>if  GTR 0 (


请帮助我解决此问题,这确实使我花了一些时间来研究问题.


Kindly help me solve this issue , its really taking me time to dig in the issue.

推荐答案

批处理在执行之前会分析整个命令,即使它分散在多行中也是如此.作为该过程的一部分,它将用<%>替换%c%时的值VAR,即之前.

Batch parses an entire command, even if it's spread across multiple lines, before executing it. As part of that procedure, it substitutes ANY %var% variable for the value VAR has at the time it was PARSED - that is, BEFORE it is executed.

SIZE ,因此其值被替换为(空),因此该命令被解释为IF (nothing) GTR 0

SIZE was NOT set before the IF... was parsed, so its value is replaced by (nothing) and hence the command is interpreted as IF (nothing) GTR 0

此外,文件名周围的单引号会更改文件名Dince '是有效的文件名字符.

Further, the single-quotes around the filename would change the filename dince ' is a valid filename character.

治愈方法:似乎最简单

if exist %V_TMP_FILE% (
FOR %%A IN (%V_TMP_FILE%) DO (
if %%~zA GTR %minbytesize% (
    %V_EMAIL_PATH%\postie -host:internalmail.usa.xl -to:"%V_TO_EMAIL_ID%" -from:%COMPUTERNAME%@xlgroup.com -s:"%V_SRC_TABLE_NM% %V_SUBJ%" -msg:"%V_MSG%" 
) else (
    echo %V_TMP_FILE% is EMPTY
)

这篇关于批处理脚本以检查文件的大小并发送邮件(如果更大)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆