1

I am trying to write a small startup-script for one of my docker-containers. The problem is that the bash-script has to wait until a artisan-command echoes "1". The artisan-commands handle-function looks like this:

$condition = something-to-check;
if($condition){ echo 1; } else { echo 0; }

What I had in mind was something like like this:

#!/bin/bash
while php artisan myapp:mycommand == "0"
do
   sleep 1m
done
do-something-else

How can I achieve this?

EDIT:

For anyone comming here via Google - James Taylor's answer pointed me in the right direction, which is why I accepted it and edit my solution in the question. The approach was to edit the handle-function like this:

/**
 * Execute the console command.
 *
 * @return int
 */
public function handle()
{
    $mycondition = true; //or whatever
    try{
        if($mycondition == false){
            echo "Some fancy status message based on the condition is false \n";
            exit(1);
        } else {
            echo "Some fancy status message based on the condition is true \n";
            exit (0);
        }
    } catch (\Exception){
        echo "Some fancy status message based on the condition with an exception\n";
        exit(1);
    }
}

And set up the bash-script like this:

#!/bin/bash
until php /path/to/artisan myapp:mycommand
do
   echo "Condition is false!" 
   sleep 1m   #or whatever you wanna do
done
echo "Condition is true!"
do-something

1 Answer 1

1

Update your my app:mycommand to return an exit code instead of echo.

exit(1);

Reference the PHP exit function: https://www.php.net/manual/en/function.exit.php

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.