Skip to content

Instantly share code, notes, and snippets.

@fcingolani
Created June 14, 2011 19:02
Show Gist options
  • Save fcingolani/1025598 to your computer and use it in GitHub Desktop.
Save fcingolani/1025598 to your computer and use it in GitHub Desktop.
Bash Script to execute wp-cron.php on a Multisite Wordpress.
#!/bin/sh
db_host="host";
db_user="user";
db_pass="password";
db_name="database";
domains=`mysql --silent --skip-column-names --host $db_host --user $db_user -p$db_pass $db_name --execute "SELECT domain FROM wp_blogs WHERE archived = '0' AND spam = '0' AND deleted = '0';"`;
for domain in $domains; do
the_date=`date`;
echo -ne "$the_date\t$domain\t";
response=`GET http://$domain/wp-cron.php`;
exit_status=$?;
if [ $exit_status != 0 ]; then
echo "ERR"
else
echo "OK"
fi
done;
@fcingolani
Copy link
Author

Thanks for your comment and work!

In my personal situation, i can't make loopback requests from my frontends to themselves, so i run this bash from a different machine.

I like the way you use curl_multi_exec, but i wonder how well it would scale in a multisite network with hundreds of blogs. I wonder it with my script too :P

@chibani
Copy link

chibani commented Feb 23, 2012

I'm going to test it on a 200+ WP
I'll adapt the script if I experience some troubles :p

@chmac
Copy link

chmac commented May 2, 2012

I forked the scrip to:

  • extract the database values from wp-config.php automatically
  • use domain and path for subdomain / mixed installs
  • use wget instead of GET

I also dropped error logging and output because in my case I don't really need it. Thanks for an excellent starting point.

@fcingolani
Copy link
Author

I'm glad it helped you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment