Skip to content

Instantly share code, notes, and snippets.

@rmpel
Last active April 23, 2024 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmpel/7b0cf45e3526e33a02c533d9e1628e69 to your computer and use it in GitHub Desktop.
Save rmpel/7b0cf45e3526e33a02c533d9e1628e69 to your computer and use it in GitHub Desktop.
WordPress Multisite universal cron.sh

WordPress Multisite universal cron.sh

Usage:

* * * * * flock -n /tmp/my-site-unique-name.lock /path/to/multisite-cron.sh

use either lines 5-8 OR 11-16, not both.

Used with

define( 'DISABLE_WP_CRON', true );

If your server has no flock command; your server is OLD; upgrade!

#!/usr/bin/env bash
# place file one folder above the public_html to prevent access from world.
cd "$(dirname "$0")/public_html"
for subsite in $(wp site list --format=csv --fields=url 2>/dev/null | tail -n+2); do
echo $subsite;
wp cron event run --due-now --url=$subsite 2>/dev/null
done
## IF YOUR SERVER tail DOES NOT SUPPORT OFFSET;
for subsite in $(wp site list --format=csv --fields=url 2>/dev/null); do
if [ "url" != "$subsite" ]; then
echo $subsite;
wp cron event run --due-now --url=$subsite 2>/dev/null
fi
done
#!/usr/bin/env bash
cd "$(dirname "$0")"
export PATH=$(pwd -P)/.local/bin:$PATH
logfile=$(pwd -P)/cron.log
cd public_html/wp
date > $logfile
for domain in $(wp site list --fields=url --archived=0 --deleted=0 | grep http); do
echo Running cron for $i >> $logfile
wp cron event run --due-now --url=$domain >> $logfile 2>&1
done
echo "Finished $(date)" >> $logfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment