[SOLVED] Run multiple bash and php scripts from a bash script
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Run multiple bash and php scripts from a bash script
I have written quite a few separate bash & scripts and php scripts that up to now I have run from cron jobs.
However I have to estimate how long each takes to run, before running the next and so it probably takes much longer than necessary to run them all. They have to run in order.
Now there are so many I am thinking it would be better to have a master bash script that would run one after the other, but I am not sure how to get the master script to wait before starting to run the next script.
Is this possible and is there a command that will make the script wait between bash and php scripts , for them to finish, before running the next?
ok, I did a test using the "wait" command and am now embararssed i had to ask, as it seems I just put wait between the calls to each script. i did a little test creating databases in php scripts, returning some records in a bash script, then updating with another php script, then another bash script to return the updated results and it seemed to work fine...
From what I have read, as long as the subscript doesnt call another subscript, the master script will wait if "wait" command is used between script calls.
Well by default you can place them in order in a script and it will execute each as the lat one finishes. The question you need to ask yourself is what do you do if
the prior script fails, ie should the subsequent script get launched or not?
I am amazed! The usual question is "how can I get all of these scripts to run at the same time?", this time it is how to get them to run in order.
Just start them in order from the main script. Do not background them, spawn off a new shell for them, or anything fancy: just run them from the main script. The default behavior is for each to exit before the next can start.
An advantage is that you can have the master script test exit codes, record start and stop times, and monitor resources (load level perhaps) as needed.
Being able to time each script is really useful, I have just put
after each "wait" at the moment, but I think if I google some date functions, I could get the script to calculate timings and print them after they have all run, which is useful. Especially as after this long process has run, something needs to be run on another server and previously i was doing it the next day, but this way I can have a much more accurate idea of how long everything is taking and get the next process to start at an appropriate time.
Load times is another thing that would be useful for me to monitor during the process, as it does at times cause a heavy load.
Thanks for the tip from Grail as well that if one fails for some reason I need to think about how to have that covered, some if statement maybe, I will have a read around today, not having heard about "exit codes" before, the phrase sounds like they may be able to be used to do that somehow.
The reason it has been done this way, was due to when I started writing the scripts, I had never written a bash script, so I was doing bit by bit and each time I had to resort to php, I was ending the bash process and calling the php. When I tried running a php script from within bash, the next bash command was executing before the php had finished, but it may be I had made some other error. At least with the various script files, it keeps the process structure clear in my mind for now, but in the future maybe I will put them all together so that they run in the foreground.