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 |