Drupal - Drush @sites not implemented in drush 9

Waiting something similar, I wrote this small script I called "drall" you may adapt:

#!/usr/bin/php
<?php

// Path to sites.php file.
include('web/sites/sites.php');

$done = [];
$argv = $_SERVER['argv'];

array_shift($_SERVER['argv']);

$parameters     = implode(' ', $_SERVER['argv']);
$commandPattern = "drush --uri=:key $parameters";

foreach ($sites as $key => $site) {

  if (count($argv) > 1 && !in_array($site, $done)) {

    $command = str_replace(':key', $key, $commandPattern);
    echo "Executing command `$command` on $site\n";
    `$command`;
    $done[] = $site;
  }
}

Use example:

$ ./drall cc render
Executing command `drush --uri=xxxxxxx cc render` on default
 [success] 'render' cache was cleared.

Hope there will be some @sites behaviors later, that was helpfull.

Although from this issue it doesn't look like it:

Drush 9 no longer supports executing a single command on multiple sites with alias lists (@A,@b,@c) or @sites. Neither of those syntaxes are available in any context. You may still use drush sa @group to see all aliases in a group; that is the only context in which Drush recognizes alias lists.


I'd simply place a lightweight loop into your ~/.bashrc or ~/.bash_profile or where ever you prefer. Just update the SITES=( foo bar ) array to your needs.

Source your bash file, cd into your multi-site root and call ddrush cim -y for example and it will iterate through all sites provided in the SITES array.

ddrush () {
  # Provide an array of sites you want to loop.
  SITES=( foo bar )

  # Validate and hint if no argument provided.
  if [ "${#}" -eq 0 ]; then
    echo "- ddrush: missing argument(s)"
    echo "EXAMPLE: ddrush cex -y"
  else
    # Loop:
    for SITE in "${SITES[@]}"; do
      echo "drush -l ${SITE} ${@}"
      drush -l "${SITE}" "${@}"
    done
  fi
}

You can use nearly the same for running a deployment script. Or you could easily provide multiple aliases like that. adrush, bdrush, cdrush – one for every multi-site environment you need to maintain.


I only now read you have 300 instances running. Respect! Well, then it might be easier to only provide an absolute path to the sites folder and have that scanned and then looped through automatically.

xdrush () {
  # Provide the absolute path to the sites directory.
  SITES="/var/www/MYMULTISITE/sites"

  # Validate and hint if no argument provided.
  if [ "${#}" -eq 0 ]; then
    echo "- xdrush: missing argument(s)"
    echo "EXAMPLE: xdrush cex -y"
  else
    PWD=${PWD}
    cd "${SITES}"
    # Loop:
    for SITE in $(ls -d */ | cut -f1 -d'/'); do
      # Skip default site.
      if [ ! "${SITE}" == "default" ]; then
        cd "${PWD}"
        echo "drush -l ${SITE} ${@}"
        drush -l "${SITE}" "${@}"
      fi
    done
  fi
}