0

By "adjacent cron tasks" I mean to tasks doing things of the same context and in close times. For example, as for now I have these cron tasks:

0 0 * * * for dir in /var/www/html/*/; do cd "$dir" && /usr/local/bin/wp plugin update --all --allow-root; done
0 0 * * * for dir in /var/www/html/*/; do cd "$dir" && /usr/local/bin/wp core update --allow-root; done
0 0 * * * for dir in /var/www/html/*/; do cd "$dir" && /usr/local/bin/wp theme update --all --allow-root; done

As you can see these do pretty "heavy" work: They updated all plugins in several sites, upload their cores, and then their themes.

I've given 1 minute for the first task, one to the second and one to the third.

From my experience, putting them all on the first minute (minute 0), isn't problematic because cron timing is just the minimal time to start the task, but each process associated with the task would start only when it can, so I would bet that generally there isn't any problem doing so.

Anyway my question is this:

Is there (at least) a best practice to split adjacent cron tasks to later minutes in the same hour (0,1,2) in the same day, or even on different hours in the same day?

In this case my task timing would instead look like this:

0 0 * * *
0 1 * * *
0 2 * * *
1

For anything other than running a simple command, schedule a script that does the complicated processing instead of trying to do it directly in the crontab.

#!/bin/sh

for dir in /var/www/html/*/; do
    ( cd "$dir" && /usr/local/bin/wp plugin update --all --allow-root )
done

for dir in /var/www/html/*/; do
    ( cd "$dir" && /usr/local/bin/wp core update --allow-root )
done

for dir in /var/www/html/*/; do
    ( cd "$dir" && /usr/local/bin/wp theme update --all --allow-root )
done

Or even

#!/bin/sh

for dir in /var/www/html/*/; do
    ( cd "$dir" && {
        /usr/local/bin/wp plugin update --all --allow-root
        /usr/local/bin/wp core update --allow-root 
        /usr/local/bin/wp theme update --all --allow-root
      } )
done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy