I am running below command in openshift platform which produces some output
oc get pods
name status
job1 Running
job2 Completed
How to extract only status from the above result and store it in a variable using shell script.
ex : status=completed
CodePudding user response:
If you add --output=json to your commands you can use JQ to select the status. I find bash scripts great for using commands but there are a lot of drawbacks when it comes to parsing output. With JSON you can regardless of the format select the correct key.
CodePudding user response:
How to extract only status from the above result and store it in a variable using shell script.
ex : status=completed
Try status=$(oc get pods -o=custom-columns=STATUS:.status.phase --no-headers)
. You can echo $status
and see the list of status saved in the environment variable.