在BAT文件中搜索假脱机文本文件中的字符串

时间:2017-10-26 14:56:59

标签: sql database batch-file cmd scheduler

我是蝙蝠文件的完全初学者。我在解释矿山要求的情景。希望我能从你的大师那里得到确切的o / p。

这是我目前的批处理文件:
注意:OP中指定的 findstr 命令在代码中包含的注释但间距 - 嗯,谁知道? OP要编辑,请

CALL %ORACLE_HOME%/bin/sqlplus "/as sysdba" @D:\Long_Running\Long_running_job.sql > D:\Long_Running\LongrunningJobs.txt 

  call :CheckEmpty "%file%"
          powershell -ExecutionPolicy ByPass -File D:\Long_Running\Send_email_report.ps1
          goto :eof

         :CheckEmpty
       if %~z1 == 0 exit

这基本上连接SQL plus,连接为sysdba,转到存在Long_running.sql文件的位置,并将o / p转换为LongrunningJobs.txt。 从那里它会触发下一行的邮件(电源外壳)。

要求:如果我可以搜索特定字符串,请说" ABCDE"在LongrunningJobs.txt文件中如果它匹配则它应该触发邮件,否则它不应该触发邮件而只是出来。
我到底应该输入什么?我使用FINDSTR可能是我没有正确使用它,它并不顺利。邮件没有被触发。

2 个答案:

答案 0 :(得分:0)

@ECHO OFF
SETLOCAL
SET "destdir=U:\destdir"
SET "outfile=%destdir%\LongrunningJobs.txt"

:: first test : empty file
COPY /y NUL "%outfile%" >NUL 2>NUL
ECHO test 1
FINDSTR "ABCDE" "%outfile%" >NUL &&ECHO Send mail

:: second test : file NOT containing "ABCDE"
ECHO something >"%outfile%"
ECHO test 2
FINDSTR "ABCDE" "%outfile%" >NUL &&ECHO Send mail

:: third test : file containing "ABCDE"
ECHO ABCDE>>"%outfile%"
ECHO test 3
FINDSTR "ABCDE" "%outfile%" >NUL &&ECHO Send mail

GOTO :EOF

我使用destdir来防止我的系统混乱。

请注意,send mail 仅在第三种情况下回显,其中主题文件包含目标字符串。

答案 1 :(得分:0)

          FINDSTR "ABCDE" "%file%" >NUL && (
          powershell -ExecutionPolicy ByPass -File D:\Long_Running\Send_email_report.ps1
          goto :eof )

@Magoo给出了正确答案,我正在调用我不应该具有的功能。非常感谢大家。