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. Code:
#!/bin/sh |
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? |
Run several scripts from one
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
Code:
echo $(date) 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. Thanks! |
Quote:
Code:
/usr/bin/time <command> Code:
time <command> |
All times are GMT -5. The time now is 07:41 PM. |