0

I've a Program2.bat having Oracle query, which generates a file log.txt having content-structure either like:

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;

OR like:

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

I'm trying to achieve following things:

  • Action-1: Call Program2.bat, which will generate log.txt
  • Action-2: Search for the string "no rows selected" in log.txt
  • Action-3: If string found then call program1.bat
  • Action-4: If string not found then do below:

    1. call program2.bat again and

    2. Do Action-2 again at an interval of 5 mins (means keep searching for string "no rows selected" in log.txt on an interval of 5 mins untill string "no rows selected" got found ).

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

How Point-2 of Action-4 can be achieved in above script or do we have any other way to achieve all in the easiest way?

Sunny
  • 6,736
  • 10
  • 25
  • 47
  • I don't understand the question? Are you using sqlplus? – Alexander Mar 03 '14 at 06:21
  • [TIMEOUT](http://stackoverflow.com/questions/1672338/how-to-sleep-for-5-seconds-in-windowss-command-prompt-or-dos) and [FOR](http://stackoverflow.com/questions/2591758/batch-script-loop) is what you need I guess. – Yaroslav Shabalin Mar 03 '14 at 06:38
  • @Alexander..I'm using Oracle Database and I've added more information in question now. – Sunny Mar 03 '14 at 06:57

0 Answers0