Link to home
Start Free TrialLog in
Avatar of LindaC
LindaCFlag for Puerto Rico

asked on

Batch File not executing Do - Loop - Maybe a vbscript will do ? Windows 2003 Server

I have the following script but the DO - LOOP is only executing once and do not execut the "hot_CMDB_backup_end.bat".

I f the loop will execute like a loop then it will run perfectly.  The thing is that I don't know how to do it in batch file or maybe in vbscript?

Attached is the script.
set newDate=%date:~4,2%-%date:~7,2%-%date:~10%
set arg=CMDB

start C:\oracle\Dba\scripts\CMDB\hot_backup_scripts\hot_CMDB_backup.bat

C:
cd C:\Program Files\Veritas\NetBackup\bin
start bpbackup -p Windows-Servers-dbs -s %arg% -L C:\oracle\Dba\logs\CMDB\hot_backup_logs\%arg%_28_Hotback.%newDate%.log -f C:\oracle\Dba\scripts\CMDB\hot_backup_scripts\%arg%list.txt
set var_stop=1

Do 

	sleep 10
	tasklist.exe /fi "IMAGENAME eq bpbackup.exe">C:\oracle\Dba\logs\CMDB\hot_backup_logs\borrame.txt
	tasklist.exe /fi "IMAGENAME eq bpbkar32.exe”>>C:\oracle\Dba\logs\CMDB\hot_backup_logs\borrame.txt
	tasklist.exe /fi "IMAGENAME eq bpcd.exe”>>C:\oracle\Dba\logs\CMDB\hot_backup_logs\borrame.txt
	findstr /i /s "bpbackup.exe bpbkar32.exe bpcd.exe" C:\oracle\Dba\logs\CMDB\hot_backup_logs\borrame.txt
	echo error level is %errorlevel% >>C:\oracle\Dba\logs\CMDB\hot_backup_logs\logfile.txt
	if %errorlevel% equ 0 (echo Todavía está corriendo el envío a Veritas > C:\oracle\Dba\logs\CMDB\hot_backup_logs\Verificacion.log ) 
	if %errorlevel% equ 1 (echo Terminó el envio a Veritas >> C:\oracle\Dba\logs\CMDB\hot_backup_logs\Verificacion.log) & start C:\oracle\Dba\scripts\CMDB\hot_backup_scripts\hot_CMDB_backup_end.bat & Exit Do
Loop

exit;

Open in new window

Avatar of t0t0
t0t0
Flag of United Kingdom of Great Britain and Northern Ireland image

Instead of using:

    Do
    .
    .
    Loop

You need to use the GOTO statement like this (note the leading ':' (colon) character):

   :Loop
    .
    .
    Goto loop

(No need for leading ':' (colon) with the GOTO but won't hurt if you put one in as in the following):

    :Loop
    .
    .
    Goto :Loop


Avatar of LindaC

ASKER

Checking.
I see you are setting the variable 'var_stop' to '1' but you're not actually using it in your code.

Going back to your loop-thing, you could also use a conditional loop like this:

    :Loop
    .
    .
    If "%var_stop%"=="0" Goto Loop



   
Sorry, let me clarify that last one.

You could use any of these:

    :Loop
    .
    .
    If not "%var_stop%"=="1" Goto Loop

or

    :Loop
    .
    .
    If not "%var_stop%"=="0" Goto Loop

whatever way around you choose to it, it's fine....


These also work too:

    :Loop
    .
    .
    If "%var_stop%"=="0" Goto Loop
.
and

    :Loop
    .
    .
    If "%var_stop%"=="0" Goto Loop

but are the inverse of above.

Because of the space, your CD command needs double-quotes. See below...

    cd C:\Program Files\Veritas\NetBackup\bin

should be:

    cd "C:\Program Files\Veritas\NetBackup\bin"

(notice the space in 'Program Files'?)
Where are you getting %args% from?
Avatar of LindaC

ASKER

The :Loop Goto :Loop is working but I think it is not recognizing the sleep.
I have modified it to sleep 600 but it is too fast.  Is the sleep command ok?

The arg is in the second line of the code in my posting.

You can change this:

if %errorlevel% equ 1 (echo Terminó el envio a Veritas >> C:\oracle\Dba\logs\CMDB\hot_backup_logs\Verificacion.log) & start C:\oracle\Dba\scripts\CMDB\hot_backup_scripts\hot_CMDB_backup_end.bat & Exit Do 

to:

If %errorlevel% EQU 1 (
   Echo Terminó el envio a Veritas >>C:\oracle\Dba\logs\CMDB\hot_backup_logs\Verificacion.log
   Start C:\oracle\Dba\scripts\CMDB\hot_backup_scripts\hot_CMDB_backup_end.bat
   Goto :EOF
)

Open in new window

Avatar of LindaC

ASKER

Checking this new way.
ASKER CERTIFIED SOLUTION
Avatar of t0t0
t0t0
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
what's you operating system? Sleep is not compatible in all versions of windows...
if you're using an external program named SLEEP.COM or SLEEP.EXE then it should work with your O/S. Also, if SLEEP is part of your O/S DOS command then it shoulg work.
Avatar of LindaC

ASKER

About the sleep I found in this link what to do http://malektips.com/dos0017.html

Now I 'am swaping the lines, but I noticed an "else".
Do I have to include else, do I have to include end if?
In XP, we pause a batch file by using the PING command  whose output is simply redirected to the NUL device like this:

Pause for 1 second

    ping -n 1 -w 1000 127.0.0.1 >nul


Pause for 5 seconds

    ping -n 1 -w 5000 127.0.0.1 >nul


Pause for 10 seconds

    ping -n 1 -w 10000 127.0.0.1 >nul


Etc....
structure of IF is...

   IF condition (
      - do this if true
   ) ELSE (
      - do this if false
   )

The last closing bracket is the equivalent to 'End-If'
Avatar of Steve Knight
You've got most ofyour answers already by the looks of it, but I would normally pause using:

ping -n X localhost >nul

will normally wait for X-1 secs.  So use

ping -n 11 localhost >nul

for 10 secs.

You can use the -w parameter to wait for a reply BUT that only works against a local address that doesnt respond so I find the above the easiest.

Steve
sorry, didn't spot the 'set arg=CMDB' near the top...

As arg is static why not just hard-code CMDB straight into you code like this:


start bpbackup -p Windows-Servers-dbs -s CMDB -L "C:\oracle\Dba\logs\CMDB\hot_backup_logs\CMDB_28_Hotback.%newDate%.log"

Open in new window

Good point dragon-it

To clarify, this should pause fo 10 seconds...

    ping -n 10 127.0.0.1 >nul

Avatar of LindaC

ASKER

Now it worked and thank you!

It also was not working because two double quotes where different in the tasklist "lines"  , see the double quotes in line 15 and 16 and compare it to line 14.  The double quotes in lines 15 and 16 where interpreted as some "strange" special character and it resulted in "ERROR: Invalid query".
I fix it and with your help it worked succesfully now:

See the result:

19:36:02 INF - END C:\Program Files\Veritas\NetBackup\bin\bpend_notify.Windows-Servers-dbs.CMDB.BAT
19:36:03 INF - Backup by oracle on client primadb using policy Windows-Servers-dbs, sched CMDB:the requested operation was successfully completed

Backup ended 19:36:02

And tablespaces where put in end backup mode in this time:

TO_CHAR(SYSDATE,'MM-DD-YY-HH24:MI:SS')                                          
---------------------------------------------------------------------------    
03-27-10-19:37:15                                                              


Tablespace altered.

Avatar of LindaC

ASKER

Excellent!
Avatar of LindaC

ASKER

I 'am just posting the resulting HOT_BACKUP.bat (which is the father script that calls veritas):

set newDate=%date:~4,2%-%date:~7,2%-%date:~10%
set arg=CMDB

start C:\oracle\Dba\scripts\CMDB\hot_backup_scripts\hot_CMDB_backup.bat

C:
cd "C:\Program Files\Veritas\NetBackup\bin"
start bpbackup -p Windows-Servers-dbs -s %arg% -L C:\oracle\Dba\logs\CMDB\hot_backup_logs\%arg%_28_Hotback.%newDate%.log -f C:\oracle\Dba\scripts\CMDB\hot_backup_scripts\%arg%list.txt
set var_stop=1

:Loop

      call C:\oracle\Dba\scripts\CMDB\hot_backup_scripts\WAIT.bat 15
      tasklist.exe /fi "IMAGENAME eq bpbackup.exe">C:\oracle\Dba\logs\CMDB\hot_backup_logs\borrame.txt
      tasklist.exe /fi "IMAGENAME eq bpbkar32.exe">>C:\oracle\Dba\logs\CMDB\hot_backup_logs\borrame.txt
      tasklist.exe /fi "IMAGENAME eq bpcd.exe">>C:\oracle\Dba\logs\CMDB\hot_backup_logs\borrame.txt
      findstr /i /s "bpbackup.exe bpbkar32.exe bpcd.exe" C:\oracle\Dba\logs\CMDB\hot_backup_logs\borrame.txt
      if %errorlevel% equ 0 (
            echo Todavía está corriendo el envío a Veritas > C:\oracle\Dba\logs\CMDB\hot_backup_logs\Verificacion.log
            echo error level is %errorlevel% >>C:\oracle\Dba\logs\CMDB\hot_backup_logs\logfile.txt
            Goto :Loop
       ) else (
            echo Terminó el envio a Veritas >> C:\oracle\Dba\logs\CMDB\hot_backup_logs\Verificacion.log
            echo error level is %errorlevel% >>C:\oracle\Dba\logs\CMDB\hot_backup_logs\logfile.txt
            start C:\oracle\Dba\scripts\CMDB\hot_backup_scripts\hot_CMDB_backup_end.bat
            Goto :Terminar
      )

:Terminar
      exit;
Instead of using long paths throughout the batch file I would have preferred something along these lines. (I haven't test this code but it choud give you a general idea).


:: ===============================================================
:: Your batch file title
::
:: ===============================================================
@echo off

set WorkingDirectory=C:\Program Files\Veritas\NetBackup\bin
set Logs=C:\oracle\Dba\logs\CMDB\hot_backup_logs
set Scripts=C:\oracle\Dba\scripts\CMDB\hot_backup_scripts

set LogFile=%Logs%\logfile.txt
set VerifyFile=%Logs%\Verificacion.log
set BorrameFile=%Logs%\borrame.txt

start "%Scripts%\hot_CMDB_backup.bat"

cd /d "%WorkingDirectory%"

set Server=CMDB
set Today=%Date:~4,2%-%Date:~7,2%-%Date:~10%
set Policy=Windows-Servers-dbs
set LogFile=%Logs%\CMDB_28_Hotback.%Today%.log
set FileList=%Scripts%\CMDBlist.txt

start bpbackup -p %Policy% -s %Server% -L "%LogFile%" -f "%FileList%"

:Loop
   call "%Scripts%\WAIT.bat 15"

   (  tasklist /fi "IMAGENAME eq bpbackup.exe"
      tasklist /fi "IMAGENAME eq bpbkar32.exe"
      tasklist /fi "IMAGENAME eq bpcd.exe"
   )>"%BarromeFile%"
   
   findstr /i /s "bpbackup.exe bpbkar32.exe bpcd.exe" "%BorrameFile%"
        
   if %errorlevel% equ 0 (
      echo Todavía está corriendo el envío a Veritas>"%VerifyFile%"
      echo error level is %errorlevel%>>"%LogFile%"
      goto :Loop
   )

   echo Terminó el envio a Veritas>>"%VerifyFile%"
   echo error level is %errorlevel%>>"%LogFile%"
   start "%Scripts%\hot_CMDB_backup_end.bat"
exit
Oh, by the way, I'm not sure if these are what you intend them to be:

(From my code above) This will create a new file

   )>"%BarromeFile%"

whereas, this will append to an existing file:

   )>>"%BarromeFile%"



As the other 3 ECHO lines have '>>', I'm not sure if you meant this one to be just:

   echo Todavía está corriendo el envío a Veritas>"%VerifyFile%"


Finally, if your existing code works well then you need not implement my suggested code. It's merely to demonstrate a different structure and compactness.

I now consider the question closed. Thank you for the points etc...

Avatar of LindaC

ASKER

I will definitely test *more later*.
The single redirection is ok, as it will be written on again and again until the %errorlevel% =1


Bye, I have to go now, but later I will test.
Avatar of LindaC

ASKER

This part is not working from your last Modified - New script:

set WorkingDirectory=C:\Program Files\Veritas\NetBackup\bin
set Logs=C:\oracle\Dba\logs\CMDB\hot_backup_logs
set Scripts=C:\oracle\Dba\scripts\CMDB\hot_backup_scripts
Set History=C:\oracle\Dba\logs\Historial

set LogFile=%Logs%\logfile.txt
set VerifyFile=%Logs%\Verificacion.log
set BorrameFile=%Logs%\borrame.txt
set HistoryFile=%History%\CMDB_hotbackup_HISTORIAL.log
set Server=CMDB
set Today=%Date:~4,2%-%Date:~7,2%-%Date:~10%
set Policy=Windows-Servers-dbs
set LogFile=%Logs%\CMDB_Hotback.%Today%.log
set FileList=%Scripts%\CMDBlist.txt

:Queued
 
  (  tasklist /fi "IMAGENAME eq oracle.exe"
      tasklist /fi "IMAGENAME eq oracle.exe"
      tasklist /fi "IMAGENAME eq oracle.exe"
   )>"%BarromeFile%"

:Loop



C:\oracle\Dba\scripts\CMDB\hot_backup_scripts>(
tasklist /fi "IMAGENAME eq oracle.exe"
 tasklist /fi "IMAGENAME eq oracle.exe"
 tasklist /fi "IMAGENAME eq oracle.exe"
) 1>""
The system cannot find the path specified.


Avatar of LindaC

ASKER

A typo - instead of Barrome is Borrame.
Sorry, you are right. it was a typo.

it was only meant to be a reworking of your own code. I mainly did a lot of cutting and pasting.

Did you get it working in the end?
Avatar of LindaC

ASKER

It is working now, but I have to get rid of the double quotes when calling the start "%Scripts%\hot_CMDB_backup.bat".

Also the writing of the borrame.txt is giving me sometimes the following messages that it is not giving in the original.  I have attached both the first one with the additinal loop named "Queued", which is waiting for some process of veritas to showed up, because in some cases Veritas Queued the jobs if they are many at the same time and it has to "wait".
The other modification is the loop "Terminar", which "unified the Veritas log with the alter tablespace log.

Original is named HOT_BACKUP.bat and yours is Test2.bat.

C:\oracle\Dba\logs\CMDB\hot_backup_logs\borrame.txt:bpcd.exe
  6612 Console                    0      6,104 K
The process cannot access the file because it is being used by another process.
C:\oracle\Dba\logs\CMDB\hot_backup_logs\borrame.txt:bpbkar32.exe
  8044 Console                    0     35,184 K
C:\oracle\Dba\logs\CMDB\hot_backup_logs\borrame.txt:bpcd.exe
  6612 Console                    0      6,104 K
The process cannot access the file because it is being used by another process.
C:\oracle\Dba\logs\CMDB\hot_backup_logs\borrame.txt:bpbkar32.exe
  8044 Console                    0     35,184 K
C:\oracle\Dba\logs\CMDB\hot_backup_logs\borrame.txt:bpcd.exe
  6612 Console                    0      6,104 K
The process cannot access the file because it is being used by another process.
C:\oracle\Dba\logs\CMDB\hot_backup_logs\borrame.txt:bpbkar32.exe
  8044 Console                    0     35,176 K
The process cannot access the file because it is being used by another process.
C:\oracle\Dba\logs\CMDB\hot_backup_logs\borrame.txt:bpcd.exe
  6036 Console                    0      6,104 K
C:\oracle\Dba\logs\CMDB\hot_backup_logs\borrame.txt:bpcd.exe
  7776 Console                    0      6,104 K------>Here it did not gave the message
error level is
C:\oracle\Dba\logs\CMDB\hot_backup_logs\borrame.txt:bpcd.exe
  6036 Console                    0      6,104 K
C:\oracle\Dba\logs\CMDB\hot_backup_logs\borrame.txt:bpcd.exe
  7776 Console                    0      6,104 K
error level is
C:\oracle\Dba\logs\CMDB\hot_backup_logs\borrame.txt:bpcd.exe
  6036 Console                    0      6,104 K
C:\oracle\Dba\logs\CMDB\hot_backup_logs\borrame.txt:bpcd.exe
  7776 Console                    0      6,104 K
error level is
C:\oracle\Dba\logs\CMDB\hot_backup_logs\borrame.txt:bpcd.exe
  6036 Console                    0      6,104 K
C:\oracle\Dba\logs\CMDB\hot_backup_logs\borrame.txt:bpcd.exe
  7776 Console                    0      6,104 K
error level is
C:\oracle\Dba\logs\CMDB\hot_backup_logs\borrame.txt:bpcd.exe
  6036 Console                    0      6,104 K
C:\oracle\Dba\logs\CMDB\hot_backup_logs\borrame.txt:bpcd.exe
  7776 Console                    0      6,104 K
error level is

===========================
The HOT_BACKUP.bat is not giving those messages:  see:

 echo error level is 0  1>>C:\oracle\Dba\logs\CMDB\hot_backup_logs\logfile.txt


C:\Program Files\Veritas\NetBackup\bin>tasklist.exe /fi "IMAGENAME eq bpbkar32.e
xe" 1>C:\oracle\Dba\logs\CMDB\hot_backup_logs\borrame.txt

C:\Program Files\Veritas\NetBackup\bin>tasklist.exe /fi "IMAGENAME eq bpcd.exe"
1>>C:\oracle\Dba\logs\CMDB\hot_backup_logs\borrame.txt

C:\Program Files\Veritas\NetBackup\bin>findstr /i /s "bpbkar32.exe bpcd.exe" C:\
oracle\Dba\logs\CMDB\hot_backup_logs\borrame.txt
C:\oracle\Dba\logs\CMDB\hot_backup_logs\borrame.txt:bpbkar32.exe
  6044 Console                    0     35,116 K

C:\Program Files\Veritas\NetBackup\bin>if 0 EQU 0 (
echo Todavfa estß corriendo el envfo a Veritas  1>C:\oracle\Dba\logs\CMDB\hot_ba
ckup_logs\Verificacion.log
 echo error level is 0  1>>C:\oracle\Dba\logs\CMDB\hot_backup_logs\logfile.txt

 Goto :Loop
)  else (
echo Termin= el envio a Veritas  1>>C:\oracle\Dba\logs\CMDB\hot_backup_logs\Veri
ficacion.log
 echo error level is 0  1>>C:\oracle\Dba\logs\CMDB\hot_backup_logs\logfile.txt

 start C:\oracle\Dba\scripts\CMDB\hot_backup_scripts\hot_CMDB_backup_end.bat
 Goto :Terminar
)

C:\Program Files\Veritas\NetBackup\bin>call C:\oracle\Dba\scripts\CMDB\hot_backu


Test2.bat.txt
HOT-BACKUP.bat.txt
Avatar of LindaC

ASKER

I have a question posted in this link because it is another server and executing in E drive:

03/28/10 11:30 PM, ID: 25580461 | Points: 250

Batch file - Executing - in Drive E: - The system cannot find the path specified
Are you up and running now or do require further assistance?