0

I am trying to get the status of an api call and check if it is Success or Failure based on this result api call continues. If it is Success or Failure then exit if condition and loop else continue to call the api to check status.

script :

#!/bin/sh
while true; do
    status_check=sudo docker exec $ContainerID calm describe app "test_status" | grep "\"action_create" | cut -c29- | cut -d ")" -f1
    echo "${status_check}"
    if [ "${status_check}" == "SUCCESS" ] || [ "${status_check}" == "FAILURE" ]
    then
        echo "Break"
        break
    else
        sleep 60s
        $status_check
     fi
done

For the above script output is : The output is already trimmed to get the specifically but still when its executed below 3 lines are streamed out. I need just the 3rd line to check the condition. It can be RUNNING or POLICY_EXEC or FAILURE or SUCCESS. It has to exit the if condition and loop only for SUCCESS or FAILURE.

[2022-12-29 19:26:34] [INFO] [calm.dsl.cli.apps:148] test_status found
[2022-12-29 19:26:34] [INFO] [calm.dsl.cli.apps:157] Fetching app details
SUCCESS
Barmar
  • 741,623
  • 53
  • 500
  • 612
NagalaeVik
  • 13
  • 4
  • 1
    You need `$(...)` around the command in the `status_check=` line. – Barmar Dec 29 '22 at 19:59
  • @Barmar Thanks a lot! Its working as expected. – NagalaeVik Dec 29 '22 at 20:04
  • However I am getting "tests.sh: line 11: POLICY_EXEC: command not found". As I already mentioned the status can be RUNNING or POLICY_EXEC or FAILURE or SUCCESS. I tried using eval "$status_check" after sleep. But still not working. – NagalaeVik Dec 29 '22 at 20:29
  • Sounds like you may have put a space after `status=`. There should be no space between `status=` and `$(sudo docker exec ...)` – Barmar Dec 29 '22 at 20:30
  • There is no space status_check=$(sudo docker exec ...) – NagalaeVik Dec 29 '22 at 20:34
  • The problem is this line: `$status_check` That's trying to execute the status as a command. I think you want `echo "$status_check"` – Barmar Dec 29 '22 at 20:37
  • But I'm not sure why you need that at all, since you already echo it before the `if` statement. You could do something like `echo "Waiting"` – Barmar Dec 29 '22 at 20:38
  • Thanks for the quick help. I need this task to be completed and send a status to the following tasks. Other scripts which are dependent on this task for completion. – NagalaeVik Dec 29 '22 at 20:49
  • The following task can use the variable `$status_check` after the loop is done. – Barmar Dec 29 '22 at 20:51
  • Yes that can be done. I will modify accordingly thanks :) – NagalaeVik Dec 29 '22 at 20:55

0 Answers0