Shell script for updating production sites


Hi everyone!

I made a bash script for updating all of my production sites. Maybe you guys will find it useful.

Most importantly though, I’d love to get feedback on how to improve it and/or any downsides you foresee to using this method.

FYI: my clients don’t have the requirement of their sites having 99% uptime: ie. it’s ok for their site to go down for a day (not often) if it saves me time on workflow


Update all production sites: ./ -a
Update specific sites: ./ -s site1 site2 site3


The usage for site1 depends heavily on your folder names. All my sites for this example are .com. The parameters site1 site2 etc. are all the root domain, minus the suffix. My folder structure is consistent with this. For example:

  • Project folder: ~/Sites/Development/DO-example
  • Bedrock folder: ~/Sites/Development/DO-example/example
  • URL:

To work in all scenarios, you would need to pass in the full domain name and appropriately name your project folder and bedrock folder. For this you would adjust the script slightly. For example:

  • Project folder: ~/Sites/Development/
  • Bedrock folder: ~/Sites/Development/
  • URL:

If I have a staging site, I add an if statement inside the update script. For example:

if [[ "$SITE" = "example" ]]; then
    ./bin/ production staging."$SITE".com
    ./bin/ production "$SITE".com

Full Script


# Update all sites
update_all () {
  read -r -p "Would you really like to update all production sites? [y/N] " response

  if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then

  update_list site1 site2 site3


## Update list of sites
update_list () {
  for SITE in "$@"
    cd ~/Sites/Development/DO-"$SITE"/"$SITE" &&
    composer update &&
    git commit composer.lock -m "wordpress updates" &&
    git push
    cd ../trellis &&
	./bin/ production "$SITE".com
	### Open site in browser to make sure nothing is broken
	open https://"$SITE".com

## Loop through script arguments
unset -v sub
while getopts "has:" OPTION
    case $OPTION in
        echo "All sites finished updating"
        until [[ $(eval "echo \${$OPTIND}") =~ ^-.* ]] || [ -z $(eval "echo \${$OPTIND}") ]; do
            sub+=($(eval "echo \${$OPTIND}"))
            OPTIND=$((OPTIND + 1))
        update_list ${sub[@]}
        echo "-a : updates all sites"
        echo "-s : update selected sites (usage: -s site1 site2)"
        echo "Use the -h flag for the help menu"

Managing the update process for a large number of sites

This is cool, thanks for sharing!

Do you have staging servers? I’d be interested in using this (on a daily cron) to automatically update minor versions of plugins and WP on my staging branches & servers. Once verified that things are all :ok_hand: on staging, I’d merge the changes into master.

Nowadays I’ve got CircleCI (free) handling the deploys for my Trellis sites, so commits to staging trigger a deploy to staging, and then commits to master trigger a deploy for production.


I really need to work in branches. Do you have an outline of your branch workflow anywhere? Every time I’ve tried to use them I’ve messed something up.


I use the feature branch workflow -


@benword Thank you :slight_smile:

I don’t have separate staging servers currently, but your workflow totally makes sense and is much more safe than pushing updates directly to production.

Thanks for sharing about CircleCI. Could you share your deploy script please?