Skip to content

Instantly share code, notes, and snippets.

@01000101
Last active November 9, 2020 21:03
Show Gist options
  • Select an option

  • Save 01000101/23c08359b9304b415cb5a7227dd3187b to your computer and use it in GitHub Desktop.

Select an option

Save 01000101/23c08359b9304b415cb5a7227dd3187b to your computer and use it in GitHub Desktop.
Updates all standard WordPress sites hosted on a cPanel server - both core and plugins. Also snoops for WP installs in a root directory (sub-sites).
#!/bin/bash
for i in `/usr/local/cpanel/bin/apitool listaccts --output json | jq -r '.data.acct[] | select(.suspended == 0) | .user'`; do
echo "Updating account: ${i}";
su -s /bin/bash -c "wp core update --path=/home/${i}/public_html/" $i;
su -s /bin/bash -c "wp plugin update --path=/home/${i}/public_html/ --all" $i;
for subsite in `find /home/${i}/public_html/ -name "wp-config.php" | grep -Po "/home/${i}/public_html/\K.*(?=/wp-config.php)"`; do
echo "Updating sub-site account: ${subsite}";
su -s /bin/bash -c "wp core update --path=/home/${i}/public_html/${subsite}/" $i;
su -s /bin/bash -c "wp plugin update --path=/home/${i}/public_html/${subsite}/ --all" $i;
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment