Skip to content

Instantly share code, notes, and snippets.

@tomlobato tomlobato/update_wp.sh

Last active Apr 22, 2017
Embed
What would you like to do?
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
You can’t perform that action at this time.