function drush_ssh_site_ssh

8.0.x drush_ssh_site_ssh($command = NULL)
6.x drush_ssh_site_ssh($command = NULL)
7.x drush_ssh_site_ssh($command = NULL)
5.x drush_ssh_site_ssh($command = NULL)
master drush_ssh_site_ssh($command = NULL)

Command callback.


commands/core/, line 35
The drush site-ssh command for connecting to a remote alias' server via SSH, either for an interactive session or to run a shell command.


function drush_ssh_site_ssh($command = NULL) {
  // Get all of the args and options that appear after the command name.
  $args = drush_get_original_cli_args_and_options();
  // n.b. we do not escape the first (0th) arg to allow `drush ssh 'ls /path'`
  // to work in addition to the preferred form of `drush ssh ls /path`.
  // Supporting the legacy form means that we cannot give the full path to an
  // executable if it contains spaces.
  for ($x = 1; $x < count($args); $x++) {
    $args[$x] = drush_escapeshellarg($args[$x]);
  $command = implode(' ', $args);
  if (!$alias = drush_get_context('DRUSH_TARGET_SITE_ALIAS')) {
    return drush_set_error('DRUSH_MISSING_TARGET_ALIAS', 'A remote site alias is required. The way you call ssh command has changed to `drush @alias ssh`.');
  $site = drush_sitealias_get_record($alias);
  // We only accept remote aliases.
  if (empty($site['remote-host'])) {
    drush_set_error('DRUSH_SITE_SSH_REMOTE_ALIAS_REQUIRED', dt('@alias does not specify a remote-host.', array('@alias' => $alias)));

  // If we have multiple sites, run ourselves on each one. Set context back when done.
  if (isset($site['site-list'])) {
    if (empty($command)) {
      drush_set_error('DRUSH_SITE_SSH_COMMAND_REQUIRED', dt('A command is required when multiple site aliases are specified.'));
    foreach ($site['site-list'] as $alias_single) {
      drush_set_context('DRUSH_TARGET_SITE_ALIAS', $alias_single);
    drush_set_context('DRUSH_TARGET_SITE_ALIAS', $alias);

  $interactive = FALSE;
  $cd = drush_get_option('cd', TRUE);
  if (empty($command)) {
    $command = 'bash -l';
    $interactive = TRUE;
  $cmd = drush_shell_proc_build($site, $command, $cd, $interactive);
  $status = drush_shell_proc_open($cmd);
  if ($status != 0) {
    return drush_set_error('DRUSH_SITE_SSH_ERROR', dt('An error @code occurred while running the command `@command`', array('@command' => $cmd, '@code' => $status)));