-2

I am doing a query:

az aks nodepool show \                                                                  ⎈ 
                --resource-group $RESOURCE_GROUP_NAME \
                --cluster-name $CLUSTER_NAME \
                --name $NODE_POOL_NAME -o table

I get output with a table name ProvisiongState. I need some help to gather that result from that query into a variable, so that I can run checks on it until it turns from UpgradingNodeImageVersion to Succeeded. I was thinking of doing this as a shell script or maybe Python program.

Table I need to get info from: enter image description here Thank you!

EDIT: I used this command to get what I needed. Thank you all for the help!

az aks nodepool show --resource-group $RESOURCE_GROUP_NAME --cluster-name $CLUSTER_NAME --name $NODE_POOL_NAME | grep "\"provisioningState\": \"Succeeded\""
  • What does it print out? If there's a key string, you can do it in a shell script with `grep`. `grep` returns a status code for whether the string was found or not. – Tim Roberts Dec 30 '21 at 20:02
  • @TimRoberts Updated the main post with example output. Thanks. – Bobby Baboon Dec 30 '21 at 20:24
  • For people to be able to test samples, you should provide example output **as text**, not screenshots. We can't pipe your screenshot into an answer to see if it behaves right in practice, so doing this means you get untested answers (at least, untested by people don't have `az` and the prerequisites to use it). See also [Why not upload images of code/errors when asking a question?](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question) – Charles Duffy Dec 31 '21 at 00:07
  • BTW, is there a reason you're using `-o table` instead of something easier to parse? `-o json` for example would let `jq` pick out the exact data you need, or `-o tsv` would lend itself to a trivial answer using awk. – Charles Duffy Dec 31 '21 at 00:21
  • ...what you end up with might be something like `az ... -o json | jq -r '.[].ProvisioningState'`, but I couldn't say for sure without seeing the output of `az ... -o json` to see what it actually calls the relevant field. – Charles Duffy Dec 31 '21 at 00:23

1 Answers1

1
az aks nodepool show \                                                                  
                --resource-group $RESOURCE_GROUP_NAME \
                --cluster-name $CLUSTER_NAME \
                --name $NODE_POOL_NAME -o table |
    grep -q UpgradingNodeImageVersion && echo Not done || echo Done

Or

az aks nodepool show \                                                                  
                --resource-group $RESOURCE_GROUP_NAME \
                --cluster-name $CLUSTER_NAME \
                --name $NODE_POOL_NAME -o table |
    grep -q Succeeded && echo Done || echo Not done
Tim Roberts
  • 48,973
  • 4
  • 21
  • 30
  • `a && b || c` is **not** the same as `if a; then b; else c` -- you can have both `b` and `c` run, so `c` can happen even when `a` was not false. Granted, it's probably okay when both `b` and `c` are in fact `echo` commands writing to the same destination (if one fails, the other probably will do so as well), but teaching it without caveats leaves folks liable to try to apply the example when that constraint isn't true. – Charles Duffy Dec 31 '21 at 00:12
  • 1
    (also, if this answers the question, that means the question is a duplicate of [Checking if output of a command contains a certain string in a shell script](https://stackoverflow.com/questions/16931244/checking-if-output-of-a-command-contains-a-certain-string-in-a-shell-script)). – Charles Duffy Dec 31 '21 at 00:24