Skip to content

Instantly share code, notes, and snippets.

@tomlobato
Last active April 22, 2017 16:47
Show Gist options
  • Save tomlobato/9c8edd0b1dc5a5649271862edb3ed99e to your computer and use it in GitHub Desktop.
Save tomlobato/9c8edd0b1dc5a5649271862edb3ed99e to your computer and use it in GitHub Desktop.
Update wordpress installations via cron
#!/bin/bash
# /etc/crontab
# 0 8 * * * root update_blogs.sh >> /var/log/update_blogs.log
admin_mail=my@email.com
blogs=`ls -d /var/www/{blog1,blog2,blog3}`
update_wp(){
blog=$1
echo "---- Updating $blog..."
user=`stat -c "%U" $blog`
output=`sudo -u $user -i -- wp core update --path=$blog 2>&1 &&
sudo -u $user -i -- wp core update-db --path=$blog 2>&1 &&
sudo -u $user -i -- wp core language update --path=$blog 2>&1 &&
sudo -u $user -i -- wp plugin update --all --path=$blog 2>&1 &&
sudo -u $user -i -- wp theme update --all --path=$blog 2>&1`
if [ $? != 0 ]; then
echo $output | mail -s "Error updating blog $blog" $admin_mail
fi
echo $output
echo
}
echo
echo
echo "============== `date` =============="
echo
for blog in $blogs; do
update_wp $blog
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment