0
#!/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 )

3 Answers 3

4

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 
Sign up to request clarification or add additional context in comments.

4 Comments

does php /var/www/get.php > get.txt have the same effect(to run in the background) as php /var/www/get.php & ?
@Michael, no. That just redirects the output. It still runs in the foreground. Background means that the parent starts the child and keeps going (so they run side-by-side). Foreground means parent will wait for child to finish, which is unaffected by output redirection.
reading man bash, I'm kinda confused at "If n is not given, all currently active child processes are waited for". Doesn't that mean just one wait is necessary? CMIIW
@pepoluan, sorry, you're right, the loop isn't needed here since wait will wait for them all. I must be confusing it with one of my many other languages I purport to know :-) I'll fix it up.
0
#!/bin/bash for((i=1;i <=10;i++)) do php /var/www/get.php & done 

Just add an ampersand.

Comments

0

Another variation :

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.