递归while循环在docker cmd中 [英] Recursive while loop in docker cmd
本文介绍了递归while循环在docker cmd中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在docker容器中运行google chrome。我已经能够成功地这样做,但有一些情况下,chrome不会运行在一些容器(大量创建容器)。
I'm trying to run google chrome inside docker containers. I have been able to successfully do so, however there have been instances where chrome would not run on some of the containers (mass creation of containers).
所以我希望运行一个while循环,直到chrome进程被发现运行。我尝试了以下操作但出现错误,例如bash:[if:command not found]
So I'm looking to run a while loop till the chrome process is found to be running. I've tried the following but with errors like "bash: [if: command not found"
var chrome_command = 'google-chrome --user-data-dir=/home/ubuntu/chrome-user-dir';
var cmd = '';
cmd += 'Xvfb :99 & ';
cmd += 'export DISPLAY=:99 & ';
cmd += 'x11vnc -rfbport 6001 -display :99 -bg -q & ';
cmd += 'while [if ps aux | grep "google-chrome"|grep -v grep > /dev/null]; do ' + chrome_command + '; sleep 1 ; done';
有人能指出我的错误!谢谢!
Could someone point out where I am going wrong! Thanks!
推荐答案
最后一行应为:
cmd += 'while ! ps aux | grep -v grep | grep -q chrome; do ' + chrome_command + '; sleep 1 ; done';
-
-q
grep
就足以看出输入中是否有匹配的行。 - 使用
!
来否定命令列表的结果。 - 似乎
google-chrome
code> ps aux 。 -q
for the lastgrep
would suffice to see if there's matched lines in the input.- Use
!
to negate the result of list of commands. - It seems
google-chrome
won't appears inps aux
.
这篇关于递归while循环在docker cmd中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文