0

I'm trying to script something up to completely automate synching sites around, and I want to be able to get a value out of the site alias which is an array.

If I do a

root@dev-drupal-www:~# drush sa @www.mysite.org.au
$aliases['www.mysite.org.au'] = array (
  'remote-host' => 'prod-drupalsites',
  'remote-user' => 'root',
  'uri' => 'www.mysite.org.au',
  'root' => '/vhost/www.mysite.org.au',
  'path-aliases' => 
  array (
    '%site' => 'sites/default/',
    '%files' => 'sites/default/files',
    '%dump' => '/tmp/drush_www.mysite.org.au.sql',
  ),
);
root@dev-drupal-www:~# drush sa @www.mysite.org.au --component="path-aliases"
Array
root@dev-drupal-www:~# drush sa @www.mysite.org.au --component="path-aliases:%dump"
The element path-aliases:%dump was not found in the alias record for @www.mysite.org.au.                                                                                                          [error]
root@dev-drupal-www:~# 

How can I extract an item from the path-aliases?

Thanks!

1

Unfortunately, (as you discovered), the site-alias command is not flexible enough to do what you want. There are other ways, though. For your specific example above, which happens to involve paths, you can use the drupal-directory (dd) command:

$ drush dd @www.mysite.org.au:%dump
/tmp/drush_www.mysite.org.au.sql
$ drush dd @www.mysite.org.au:%files
/vhost/www.mysite.org.au/sites/default/files

For a more general-purpose solution, you could use the php-eval (ev) command:

$ drush ev '$a = drush_sitealias_get_record("@gk.dev"); print_r($a["path-aliases"]);'
Array
(
    [%boo] => /usr/local/boo
    [%root] => /srv/www/dev.greenknowe.org
)

This can, of course, be customized to suit, as the ev command will evaluate any arbitrary php you care to throw at it (as long as you escape special characters correctly). This is more complicated to use than the dd command, but it will also work for elements other than paths in the path-aliases element.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.