Skip to main content

In a Post process command file, I need to check two arguments before preforming an action. 

I need to check if the backup job failed (%6==2) and I need to also check the number of retries (%4==10).

I have tried:

  IF %6==2(IF %4==10( do action ))

And:

  IF %6==2 && %4==10( do action )

But neither work.

How do I test multiple arguments in a Post process?

Hey @swharrell 

First step to debug might be outputting all the arguments to a log file so you can see the values and see if it matches up to what you expect

echo %* >> arguments.txt

Here is my batch file

echo %* >> c:\stuff\args.txt
IF %6==1 (echo "Success" >> c:\stuff\args.txt)

and here was my output inside c:\stuff\args.txt

-bkplevel 1 -attempt 1 -status 1 -job 10 -cn classic -vm Instance001
"Success"

 

 


@swharrell 

You can try the following as well. 

 

@echo off
IF %6==2 (
IF %4==10 (
echo Conditions are TRUE
echo The hostname of this machine is: %COMPUTERNAME%
) ELSE (
echo Second condition is FALSE
echo Expected %4 to equal 10
)
) ELSE (
echo First condition is FALSE
echo Expected %6 to equal 2
)


echo %1 >> C:\temp\postBackup.log
echo %2 >> C:\temp\postBackup.log
echo %3 >> C:\temp\postBackup.log
echo %4 >> C:\temp\postBackup.log
echo %5 >> C:\temp\postBackup.log
echo %6 >> C:\temp\postBackup.log

#### Testing Results ####

C:\Temp>batch.bat  %1 %2 %3 11 %5 2
Second condition is FALSE
Expected 11 to equal 10

C:\Temp>batch.bat  %1 %2 %3 10 %5 2
Conditions are TRUE
The hostname of this machine is: Lab1

C:\Temp>batch.bat  %1 %2 %3 10 %5 2
Conditions are TRUE
The hostname of this machine is: Lab1

C:\Temp>batch.bat  %1 %2 %3 11 %5 2
Second condition is FALSE
Expected 11 to equal 10

C:\Temp>batch.bat  %1 %2 %3 10 %5 1
First condition is FALSE
Expected 1 to equal 2


@Damian Andre , @NVFD411

Thank you both for your responses. I have output the argument values and I do receive the expected results. The problem I am having is, the command script currently runs with no errors as:

IF %6==2(do action)

But when I try to add the second argument as either:

  IF %6==2(IF %4==10( do action ))

or

  IF %6==2 && %4==10( do action )

I receive the following error:

“The script eC:\PostCmds\Database_post.cmd] returned a nonzero code e255] which indicates it did not complete properly.”


@swharrell  - Have you tried IF %6==2 if %==10 (do action)?    Breaking out the %6 and %4 in my sample is evaluating both conditions and then doing the command if true.  Is that not how you would like it to work?

Do you mind sharing your script and I’ll test it and try to get the expected results.

 

Mark


@NVFD411 

It looks like that solution will work. In my above attempt I had the ampersands, but it appears from your suggestion and my testing they are not needed.

Thank you.


Reply