Recursive while loop in docker cmd

自作多情 提交于 2020-01-07 06:54:18

问题


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).

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!


回答1:


The last line should be:

    cmd += 'while ! ps aux | grep -v grep | grep -q chrome; do ' + chrome_command + '; sleep 1 ; done';
  • -q for the last grep 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 in ps aux.


来源:https://stackoverflow.com/questions/32169974/recursive-while-loop-in-docker-cmd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!