开发者

shell /bash script - how do I execute multiple scripts at once using while

#!/bin/bash
for((i=1;i <=10;i++))
do
  php /var/www开发者_运维百科/get.php
done

I have the above shell script that I'm using to execute get.php for 10 times . However it seems that the script(s) are executed one by one so I would like to know if it's possible to execute all of them at once (obviously without to type the php path command for 10 times )


If you want to run them all concurrently, you can change:

php /var/www/get.php

into:

php /var/www/get.php &

This runs the process in the background rather than the foreground. It's your responsibility to ensure that your script is functional when running in the background of course. You may have to watch out for resources that don't like being shared, or mingling of the outputs from the different processes.

If you also wanted to wait for all ten to finish as well, start with:

#!/bin/bash
for((i=1;i <=10;i++))
do
  php /var/www/get.php &
done
wait


#!/bin/bash
for((i=1;i <=10;i++))
do
  php /var/www/get.php &
done

Just add an ampersand.


Another variation :

seq 1 3 | while read i; do /usr/bin/php -v &; done;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜