Reputation:
How to run cron jobs one after another, like job queue ?
I am working on project which has near about 20+ cron jobs, most of them starts every hour and are very DB intensive, so i would like to have something like job queue which will start one cron job after another ,so not all 20+ job start at the start of new hour and make my server unavailable.
Is there per-built system for something like this ? or any other easy way to add job queue functionality to the linux cron. ?
Upvotes: 0
Views: 2016
Reputation: 826
Write a bash script to run the commands in sequence, and add that to the crontab.
Eg create a file called something like phpjobs.sh with the commands to run the jobs in order:-
#!/bin/bash
/usr/bin/php -q <yourfile1.php>
/usr/bin/someothercommand
/usr/bin/php -q <yourfile2.php>
/usr/bin/php -q <yourfile3.php>
then make it executable
chmod 755 phpjobs.sh
Then add it to the crontab to run every hour
0 * * * * root /path/to/phpjobs.sh
Upvotes: 6