Execute wp-cli command on all sites on server

Im pretty sure someone knows the answer, i’m trying to find a way to execute wp cli commands to all sites on my server.

So my directory structure is /srv/users/serververpilot/apps/*/public

The asterisk is where all the sites are located in, each site has a different public directory.

So I know I can run something like:

wp core update --path="/srv/users/serverpilot/apps/myfirstsite/public/"
wp core update --path="/srv/users/serverpilot/apps/mysecondsite/public/"
wp core update --path="/srv/users/serverpilot/apps/mythirdsite/public/"

However what i’m looking for is how can I mass run WordPress updates via wp cli to all sites under /srv/users/serververpilot/apps/*/public

Anyone has any pointers?

1 Answer
1

Here’s an example using find with a directory type and zero maxdepth:

$ find /srv/users/serverpilot/apps/*/public/ \
-type d \
-maxdepth 0 \
-exec /usr/local/bin/wp core update --path={} \;

or in a single line:

$ find /srv/users/serverpilot/apps/*/public/ -type d -maxdepth 0 -exec /usr/local/bin/wp core update --path={} \;

Leave a Comment