Skip to content

Instantly share code, notes, and snippets.

@corradomatt
Forked from bjornjohansen/run-wp-cron.sh
Last active September 7, 2018 16:10
Show Gist options
  • Save corradomatt/b1102c1ac3e225517d89d9c178d45543 to your computer and use it in GitHub Desktop.
Save corradomatt/b1102c1ac3e225517d89d9c178d45543 to your computer and use it in GitHub Desktop.
Run cron on all sites on a server (works with multisite) - Thanks to https://gist.github.com/bjornjohansen/a00a9fee5475c4dadb56
#!/bin/bash
# Copyright © 2018 Matt Barrett - https://github.com/corradomatt
# Special thanks to https://gist.github.com/bjornjohansen/a00a9fee5475c4dadb56
# This work is free. You can redistribute it and/or modify it under the
# terms of the Do What The Fuck You Want To Public License, Version 2,
# as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
HTML_ROOT="/var/www/html"
WP_CLI="/usr/local/bin/wp"
SITES=$(find $HTML_ROOT ! -path $HTML_ROOT -maxdepth 1 -type d -exec echo {} \;)
for WP_PATH in $SITES ; do
# If WordPress isn't installed here, we move on
if ! $(${WP_CLI} core is-installed --path="$WP_PATH" --quiet); then
echo "WordPress is not installed here: ${WP_PATH}"
continue
fi
# Get a list of site URLs
if $($WP_CLI core is-installed --path="$WP_PATH" --quiet --network); then
SITE_URLS=`${WP_CLI} site list --fields=url --archived=0 --deleted=0 --format=csv --path="$WP_PATH" | sed 1d`
else
SITE_URLS=(`${WP_CLI} option get siteurl --path="$WP_PATH"`)
fi
# Loop through all the sites
for SITE_URL in $SITE_URLS
do
${WP_CLI} cron event run --due-now --url="$SITE_URL" --path="$WP_PATH" --quiet
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment