|
Answer» I need to run a script that does the FOLLOWING:
Queries a server farm to find all servers in a "converged" state, counts the number of servers and then takes additional actions based on the count.
I'm starting with this:
Code: [Select]wlbs query <farm> /passw<password here> | find /c "converged" On the farm I'm testing against the "converged" count is 16. If the count is greater than 3 then the script should proceed to run ANOTHER set of commands. If the count (output of find /c) is less than or equal to 3 then the script should terminate.
I tried this: Code: [Select] If wlbs <farm> /passw<password here> | find /c "converged" > 3 echo Greater than 3! but it doesn't work. It outputs the results to a file named "3". I'm hoping not to have to create a text file to hold the results of the find /c command.
The WLBS query is necessary but I don't have to use find if you have another suggestion.
Your help is certainly appreciated.
Thanks,
MJYou could use FOR /F to parse the output of wlbs and put it into a variable. Something like this: (I don't have a farm to TEST it on, but it will be something very like this) Of course you understand the IP and password are just examples.
Code: [Select]for /f %%A in ( ' wlbs query 10.50.100.10 /passw pass_word ^| find /c "converged" ' ) do set NumberOfConverged=%%A if %NumberOfConverged% gtr 3 echo Greater than 3! Notes:
Variable names are not case-sensitive: %NumberOfConverged%, %NUMBEROFCONVERGED% and %numberofconverged% are the same variable, in fact any mixture of cases is OK. I like using CamelCase personally because I think it is more readable.
In the FOR dataset (the part in the brackets) you need to escape the pipe SYMBOL by preceding it with a caret.
Also in the FOR dataset I have inserted extra spaces (which are ignored) so you can see the single quotes than enclose the command) more clearly.
In batch language the comparison operators are not > < etc (these already mean something else) they are three letters long and are not case sensitive:
EQU - equal NEQ - not equal LSS - less than LEQ - less than or equal GTR - greater than GEQ - greater than or equal
Quote from: Salmon Trout on September 14, 2012, 01:20:27 PM so you can see the single quotes than enclose the command That's: "so you can see the single quotes that enclose the command"
Salmon Trout - Thank you! This works perfectly. I really appreciate the explanation of what the commands do as well. Even if I had tried using parenthesis I wouldn't have used the single quotes around wlbs query . . .
Very helpful, thank you.
MJ
|