Until string from remote command equals value run remote command

I solved my issue by using the following code

#!/bin/bash
function GET_STATUS {
     #values Active Passive Failed
     ssh  -a localhost '/home/user/fakecommand.sh'
}

STATE="unknown"
until [[ "$STATE" = "Failed" ]]
do
echo $STATE
sleep 5


STATUS=`GET_STATUS`
echo $STATUS | grep Active && STATE="Active"
echo $STATUS | grep Passive && STATE="Passive"
echo $STATUS | grep Failed && STATE="Failed"
done


bash script: I want to wait until the output from function contains certain values

Note: this function ssh's into a remote server runs a command and outputs data to standard out

function GET_STATUS {    
     ssh  -a localhost '/home/user/fakecommand.sh'
}

Unfortunately the output from the remote command changes length in both line numbers and sometimes it has extra white space..

It looks something like this....

Running command.....

variable length:stuff i dont need1                stuff i dont need2                        status                          stuff i dont need3
variable length:stuff that i dont need 1                         stuff i dont need2                        Active                          stuff i dont need3

I want to perform actions based on the value of the status column
There are only 3 values..... Active,Passive,Failed

I have written the following code, but i think it could be much better.

GET_STATUS  | grep "Active" && STATE="Active" # I Set the variable first so that i dont have to wait for the sleep if it is already in Active
        until [[ "$STATE" = "Active" ]]
                do
                echo "Running GET_STATUS" && sleep 1
                GET_STATUS  | grep "Active" && STATE="Active"
done

Can anyone think of a way i can set the the variable $STATE
Any heap would be greatly appreciated

Thanks

Please use code tags as required by forum rules!

Would be helpful if you posted a) your remote script b) an execution log thereof c) some real output.