Unable to implement IF conditional statements

Microsoft Windows server 2008 r2 standar...
September 27, 2010 at 08:00:25
Specs: Windows 2003/2008 R2, Core 2 Duo
I'm able to run it and establish it but the thing is conditional statements does not get evaluated and it executes everything. so please if anyone can shed some light and make the syncinprog subroutine a looping one where it only keeps iterating till the output of the command gives synchrozined string.


##############################Start of File#######################################
for /f "usebackq tokens=8" %%i in (`symmir query -g dgclone ^|findstr /i "dev01"`) do (

SET status=%%i

IF "%status%" == "Split" GOTO SPLIT
IF NOT "%status%" == "Split" Goto EXIT

)

:SPLIT
symmir -g dgclone establish -nop
ECHO %ERRORLEVEL%
if ERRORLEVEL 0 GOTO SYNCINPROG
IF ERRORLEVEL 1 GOTO ESTABLISHFAIL
IF ERRORLEVEL 18 GOTO ESTABLISHED
GOTO END


:ESTABLISHFAIL
Echo %ERRORLEVEL%
ECHO "Establish Operation was Unsucessful"
:END

:ESTABLISHED
Echo %ERRORLEVEL%
Echo "Devices are already in Establish state"
GOTO SYNCINPROG
:END

:SYNCINPROG
For /f "usebackq tokens=8" %%a in (`symmir query -g dgclone ^|findstr /i "dev01"`) DO
Set syncinprog=%%a
IF "%syncinprog%"=="SyncInProg"
(for /f "usebackq tokens=8" %%a in (`symmir query -g dgclone ^|findstr /i "dev01"`)) Else (
If "%syncinprog%"==""Synchronized" GOTO SYNCHRONIZED
)


:SYNCHRONIZED
echo "Device is Synchronized"
:END


:EXIT
Echo %ERRORLEVEL%
ECHO "Devices are Not in split State"
:END
#############################End of File##################################


Output of the batch:
C:\Documents and Settings\khair03>"c:\Documents and Settings\khair03\Desktop\SPLIT-ESTAB.BAT"

C:\Documents and Settings\khair03>
'' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\khair03>for /F "usebackq tokens=8" %i in (`symmir query -g dgclone |findstr /i "dev01"`) do (
SET status=%i
IF "Split" == "Split" GOTO SPLIT
IF NOT "Split" == "Split" Goto EXIT
)

C:\Documents and Settings\khair03>(
SET status=Synchronized
IF "Split" == "Split" GOTO SPLIT
IF NOT "Split" == "Split" Goto EXIT
)

C:\Documents and Settings\khair03>symmir -g dgclone establish -nop

'Incremental Establish' operation execution is in progress for
device group 'dgclone'. Please wait...


Device is already in this BCV state


C:\Documents and Settings\khair03>ECHO 18
18

C:\Documents and Settings\khair03>if ERRORLEVEL 0 GOTO SYNCINPROG
The syntax of the command is incorrect.

C:\Documents and Settings\khair03> For /f "usebackq tokens=8" %a in (`symmir query -g dgclone ^|findstr /i "dev01"`) DO

C:\Documents and Settings\khair03>


See More: Unable to implement IF conditional statements

Report •


#1
September 27, 2010 at 13:09:36
Hi dude9112,

I'm sorry I can't help you with this.

Start a batch file with "@echo off" (without quote's)
Things getting more clearly then ;]

MUs,

start iexplore.exe http://www.computing.net/cgi-bin/my... & exit


Report •

#2
September 27, 2010 at 13:29:03
Stick a label at the top, (possibly ":Start"), This:

:SYNCHRONIZED
echo "Device is Synchronized"
:END

Put and "Exit" Command.

I also need some clarification on this:

:SYNCINPROG
For /f "usebackq tokens=8" %%a in (`symmir query -g dgclone ^|findstr /i "dev01"`) DO
Set syncinprog=%%a
IF "%syncinprog%"=="SyncInProg"
(for /f "usebackq tokens=8" %%a in (`symmir query -g dgclone ^|findstr /i "dev01"`)) Else (
If "%syncinprog%"==""Synchronized" GOTO SYNCHRONIZED
)

What exactly are you trying to?

With all the syntax errors aside, All you would be doing is checking to see if it equals "syncinprog", do nothing, then check if it equals synchronized...

Give me a little bit of clarification and I'll be glad to help some more.

Can I put a question here?


Report •

#3
September 27, 2010 at 14:04:15
Thanks for the reply.. here is what i'm trying to do
In that block
:SYNCINPROG
For /f "usebackq tokens=8" %%a in (`symmir query -g dgclone ^|findstr /i "dev01"`)

#capture the output from this line in particular row at 8th column and then#
DO
Set syncinprog=%%a

#compare that string if equals to Syncinprog then reloop this same block with echoing SyncInprog#
IF "%syncinprog%"=="SyncInProg"
(for /f "usebackq tokens=8" %%a in (`symmir query -g dgclone ^|findstr /i "dev01"`))


#here compare it if its Synchronized then go to other subroutine#
Else (
If "%syncinprog%"==""Synchronized" GOTO SYNCHRONIZED
)

Here is my updated code:
I'm able to loop now with few corrections but it goes to each block and executes i want it come out of batch if the conditions are met.



Report •

Related Solutions

#4
September 27, 2010 at 14:11:32

for /f "tokens=8" %%i in ('symmir query -g dgclone ^|findstr /i "dev01"') do (
set status=%%i
IF "%%i"=="Split" GOTO SPLIT Else
IF "%%i" NEQ "Split" (
GOTO EXIT
)
)
:SPLIT
symmir -g dgclone establish -nop
IF ERRORLEVEL 0 GOTO SYNCINPROG
IF ERRORLEVEL 1 GOTO ESTABLISHFAIL
IF ERRORLEVEL 18 GOTO ESTABLISHED

GOTO EOF
:END

:SYNCINPROG
FOR /F "TOKENS=8" %%a IN ('SYMMIR QUERY -G dgclone ^|FINDSTR /I "dev01"') do ( set syncinprog=%%a
IF "%%a"=="SyncInProg" GOTO SYNCINPROG
IF "%%a"=="Synchronized" GOTO SYNCHRONIZED
Else "%%a" GOTO INVALID
)
:END
:EOF


:SYNCHRONIZED
Echo "Devices are synchronized"
:EOF

:INVALID
Echo "Invalid State"
:EOF

:EXIT
Echo "Exiting Batch"
:END

:EOF
:END



Report •

#5
September 27, 2010 at 17:46:37
Check your syntaxes. Mostly brackets.

FOR /F "tokens=8" %%a IN ('SYMMIR QUERY -G dgclone ^|FINDSTR /I "dev01"') do (
set syncinprog=%%a
IF "%%a"=="SyncInProg" GOTO SYNCINPROG
IF "%%a"=="Synchronized" (
GOTO SYNCHRONIZED
) Else (
GOTO INVALID
)
)

Also, instead of just creating a :EOF label every few commands, stick the :EOF at the end of the file, and use GOTO :EOF.

Can I put a question here?


Report •

#6
September 30, 2010 at 07:06:43
conditional statements does not get evaluated and it executes everything.
IF ERRORLEVEL checks to see if the ErrorLevel is greater than or equal to the number in question, so IF ERRORLEVEL 0 should execute if the ERRORLEVEL is positive.

Report •

Ask Question