0

I have a bash script which is executing php script. My bash knowledge is poor and I need to execute that PHP script about hundred times. I simply copy pasted the execute line:

#!/bin/bash
php /home/me/public_html/script/stats.php 1 2 3
php /home/me/public_html/script/stats.php 1 2 3
php /home/me/public_html/script/stats.php 1 2 3
...

1,2,3 are arguments i pass to php script.

All works fine, but after 8-th line bash script hangs not going into executing next. So I have to restart it again.

What can be wrong?

UPD

PHP (not full script but general idea)

It starts with retrieving command line args. Passes them to a function which uses them in a msql query. Every result of the msql query is passed to another function which uses that result to form up an url from which it retrieves a comma delimited string and processes it splitting it into array and inserting into another table. After main function completes the msql link is closed, script exits.

<?php
if (($argv[1] > 0) && ($argv[2] > 0) && ($argv[3] > 0)) {
echo "All good! Here we go: ";
echo "\n";
gatherstats($argv[1],$argv[2],$argv[3]);

} else {
echo "no\n";

}



function gatherstats($y,$m,$cl){ 

  Require 'db.php';
// SQL QUERY HERE AND A LOOP TO PROCESS RESULTS

//CALLS UP NEXT FUNCTION FOR EACH RESULT
 crawl($a,$b,$c);

}

function crawl($atr,$year,$month) { 

       //forms up specific url from passed vars and processes it

    }


  mysqli_close($link);

?>
3
  • Maybe pass a fourth argument, 100, and just do one call Commented Nov 14, 2012 at 23:22
  • Check using ps -ef how.many instances of PHP are alive at the end Commented Nov 14, 2012 at 23:25
  • @Esailija :) nope:) 1,2,3 are different per line. but their value doesn't influence the stop of the execution. I mixed them few times and replaced - still same result. @Cthulhu ps -ef give no alive php instances after the stop. Commented Nov 14, 2012 at 23:33

1 Answer 1

1

Maybe the 8th php script call hangs for some reason. You can do this to avoid typing the command 100 times:

for i in {1..100}; do
   php /home/me/public_html/script/stats.php 1 2 3 > some_log_file_$i.log
done

Add some print statements to the php script and check the log for the 8 call to see what happened. If the requirement is not to stop the calls (even if one fails), then you can make the script calls asynchronous using

for i in {1..100}; do
   php /home/me/public_html/script/stats.php 1 2 3 > some_log_file_$i.log &
done
Sign up to request clarification or add additional context in comments.

4 Comments

Great! thanks for the loop suggestion. About the printouts from PHP - they do exist. since there are also loops inside php i echo the completion of each loop cycle. All seems good. no error, nothing, just as soon as 8-th execution is complete = bash hangs:(
Check out the comment of @Cthulhu, an look for alive instances of php after the 8 call. Can you post the php code?
Cthulhu comment didn't help much unfortunately. Added php script to the post.
Can you add an echo statement after the gatherstats invocation and test again?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.