Live Blog

Introducing cron-task-runner.sh: End Overlapping Cron Jobs!

This page has had its content updated on December 10, 2025 EST by Jordan

Content Error or Suggest an Edit

Notice a grammatical error or technical inaccuracy? Let us know; we will give you credit!

Introduction

Just committed a little script to GitHub that I think some of you might find useful, especially if you deal with complex background processes. It’s called cron-task-runner.sh, and it’s designed to bring some simplicity and stability to your scheduled server tasks.

The Problem, Running Multiple Sequential Actions via Cron

The motivation for this script came from a recent issue where a site was running multiple sequential actions—specifically, a massive WP All Import followed by several critical caching and rewrite commands—all as separate cron jobs.

Here was the original sequence of tasks, designed to run one after another:

  1. Start the import.
  2. Monitor the import processing.
  3. Flush rewrites.
  4. Clear various caches.

The snag? When these are set up as separate cron entries, there’s a risk of them overlapping. If the import processing ran longer than expected, the next scheduled job (like clearing the cache) could fire prematurely. This kind of timing mismatch can lead to a “race condition,” which, in this case, resulted in temporary 404 errors being incorrectly cached by tools like Relay Redis and Object Cache Pro.

As one community member summarized:

“If the trigger or processing action runs longer than expected, the next cron… can run during the same time window. That creates a race condition…”

The Fix, a bash script cron-task-runner.sh

cron-task-runner.sh avoids this entirely. Instead of managing a complex series of separately timed cron entries, you define all your related tasks (imports, database cleanups, cache flushes, etc.) inside a single configuration file.

The script then runs all these tasks in strict sequential order under one single cron entry. Task B simply won’t start until Task A has completed, guaranteeing that your cleanup and maintenance processes execute exactly when and how they should.

This keeps your crontab tidy, your tasks orderly, and helps prevent those frustrating, intermittent errors caused by timing overlaps.

Getting Started

If you have complex, multi-step background jobs, you might want to check it out.

  1. Download the script and its configuration file.
  2. Edit the config to define your sequential commands.
  3. Set up one line in your crontab to run the runner.

This small shell script can be a big time-saver if you’ve been battling overlapping cron jobs. Feel free to grab the script and config from the repo!

wp shelltools
wp-shelltools/cron-task-runner at main · managingwp/wp-shelltools · GitHub
WordPress shell tools. Contribute to managingwp/wp-shelltools development by creating an account on GitHub.
favicongithub.com

Reporting Issues

If you have any issues, you can comment here or better yet you can open a Github issue.

0 Shares: