Performance and Multisite help — book a call with me via my Expert page on Clarity, I use this service for calls.

How to schedule bulk cron jobs in Linux? Easy peasy

  1. Login as root user through SSH (I prefer putty)
  2. To view crontab entries execute the following command: crontab -l
  3. To edit crontab directly you can use: crontab -e

But for bulk editing it’s not really convenient, right?

Instead, we’ll create an editable file with all needed entries first and then load it to crontab.

  1. Prepare crontab entries in regular .txt.

For WordPress Multisite Cron it will look something like this:

1       0       *       *       *       wget -O 'http://siteA.com/publishing.php' >/dev/null 2>&1
2       0       *       *       *       wget -O 'http://siteB.com/publishing.php' >/dev/null 2>&1
3       0       *       *       *       wget -O 'http://siteC.com/publishing.php' >/dev/null 2>&1

or you can use curl instead:

1       0       *       *       *       curl -L -s 'http://siteA.com/publishing.php' >/dev/null 2>&1
2       0       *       *       *       curl -L -s 'http://siteB.com/publishing.php' >/dev/null 2>&1
3       0       *       *       *       curl -L -s 'http://siteC.com/publishing.php' >/dev/null 2>&1

I won’t explain here crontab syntax in detail as there are loads of instructions you can easily find.

2. Create file in desired directory (that’s my root in Centos):
cat > /var/www/www-root/data/my_cron.txt
This will create file and open it for editing at once.
How to schedule bulk cron jobs in Linux? Easy peasy
You can edit it right here ( ctrl-c to past prepeared lines, ctrl-d to save ) or even through FTP if it’s more convinient to you.

Mind, that the next step will replace all existing entries in your current crontab. So in order to preserve them, remember to add them to your my_cron.txt as well.

3. Update crontab with new values:

crontab /var/www/www-root/data/my_cron.txt

4. List cron jobs to verify your crontab has been updated correctly:

crontab -l

Not that complicated, right?

From now on when it comes to corn jobs you won’t waste your time anymore adding them manually.

Better, enjoy an extra cup of coffee instead 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *