我正在嘗試為我的一個 docker 容器撰寫一個小型啟動腳本。問題是 bash 腳本必須等到工匠命令回顯“1”。artisan-commands 句柄函式如下所示:
$condition = something-to-check;
if($condition){ echo 1; } else { echo 0; }
我的想法是這樣的:
#!/bin/bash
while php artisan myapp:mycommand == "0"
do
sleep 1m
done
do-something-else
我怎樣才能做到這一點?
編輯:
對于通過 Google 來到這里的任何人 - James Taylor 的回答為我指明了正確的方向,這就是我接受它并在問題中編輯我的解決方案的原因。方法是像這樣編輯句柄函式:
/**
* 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);
}
}
并像這樣設定 bash 腳本:
#!/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
uj5u.com熱心網友回復:
更新您的 my app:mycommand 以回傳退出代碼而不是回顯。
exit(1);
參考PHP退出函式:https ://www.php.net/manual/en/function.exit.php
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/440730.html
上一篇:sed:分段資料中的模式搜索
