Last active
April 22, 2017 16:47
-
-
Save tomlobato/9c8edd0b1dc5a5649271862edb3ed99e to your computer and use it in GitHub Desktop.
Update wordpress installations via cron
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# /etc/crontab | |
# 0 8 * * * root update_blogs.sh >> /var/log/update_blogs.log | |
[email protected] | |
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