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

LVL 8
LindaCAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

t0t0Commented:
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


0
LindaCAuthor Commented:
Checking.
0
t0t0Commented:
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



   
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

t0t0Commented:
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.

0
t0t0Commented:
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'?)
0
t0t0Commented:
Where are you getting %args% from?
0
LindaCAuthor Commented:
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.
0
t0t0Commented:

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

0
LindaCAuthor Commented:
Checking this new way.
0
t0t0Commented:
To test the ERRORLEVEL of a command, the test MUST immediately follow the command.

I notice you have:

    findstr /i /s "bpbackup.exe bpbkar32.exe bpcd.exe".....
    echo error level is %errorlevel%.....
    if %errorlevel% equ 0.....

If you intend to find the ERRORLEVEL of FINDSTR then you need to swap your lines around ie,:

    findstr /i /s "bpbackup.exe bpbkar32.exe bpcd.exe".....
    if %errorlevel% equ 0 (
        REM Do this if the condition is true
    ) else (
        REM Do this if the condition is false
    )

In this case, you would have to ECHO %errorlevel% to logfie.txt for both conditions...
    echo error level is %errorlevel%.....

 
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
t0t0Commented:
what's you operating system? Sleep is not compatible in all versions of windows...
0
t0t0Commented:
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.
0
LindaCAuthor Commented:
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?
0
t0t0Commented:
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....
0
t0t0Commented:
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'
0
Steve KnightIT ConsultancyCommented:
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
0
t0t0Commented:
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

0
t0t0Commented:
Good point dragon-it

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

    ping -n 10 127.0.0.1 >nul

0
LindaCAuthor Commented:
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.

0
LindaCAuthor Commented:
Excellent!
0
LindaCAuthor Commented:
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;
0
t0t0Commented:
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
0
t0t0Commented:
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...

0
LindaCAuthor Commented:
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.
0
LindaCAuthor Commented:
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.


0
LindaCAuthor Commented:
A typo - instead of Barrome is Borrame.
0
t0t0Commented:
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?
0
LindaCAuthor Commented:
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
0
LindaCAuthor Commented:
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
0
t0t0Commented:
Are you up and running now or do require further assistance?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2003

From novice to tech pro — start learning today.