基于搜索字符串迭代批处理脚本

时间:2014-03-03 05:23:53

标签: windows batch-file oracle11g findstr

我有一个Program2.bat有Oracle查询,它会生成一个文件log.txt,其内容结构如下:

SQL> SELECT SID, SERIAL#, STATUS, USERNAME, LOGON_TIME FROM GV$SESSION WHERE USERNAME = 'DBADMIN' and status in ('ACTIVE','INACTIVE','KILLED') ;

no rows selected

SQL> spool off;

或者喜欢:

SQL> SELECT SID, SERIAL#, STATUS, USERNAME, LOGON_TIME FROM GV$SESSION WHERE USERNAME = 'DBADMIN' and status in ('ACTIVE','INACTIVE','KILLED') ;


       SID    SERIAL#    STATUS     USERNAME   LOGON_TI                                         
---------- ---------- ----------   ----------  -------------                                          
      2388         54         Active     DBADMIN     28-FEB-14                                      
      2391         37         Active     DBADMIN      17-FEB-14                                         
      2395        111        Inactive   DBADMIN      28-FEB-14                                          
      2780        325        Killed       DBADMIN      26-FEB-14                                       
      2790        111        Killed       DBADMIN      8-FEB-14                               

5 rows selected.

SQL> spool off

我正在努力实现以下目标:

  • 操作-1:调用Program2.bat,它将生成log.txt
  • 操作-2:在log.txt
  • 中搜索字符串“no rows selected”
  • 操作-3:如果找到了字符串,则调用program1.bat
  • 动作-4:如果找不到字符串,请执行以下操作:

    1. 再次调用program2.bat并

    2. 以5分钟的间隔再次执行Action-2(意味着以5分钟的间隔继续搜索log.txt中的字符串“no rows selected”,直到找到“没有选择行”字符串。)< / p>

      @echo off
      setlocal
      
      Call Program2.bat
      >nul findstr /c:"no rows selected" log.txt && (
      call program1.bat 
      ) || (
      call program2.bat
      )
      

如何在上述脚本中实现Action-4的Point-2,或者我们是否有其他方式以最简单的方式实现所有目标?

0 个答案:

没有答案