dynamic drush alias files

Alias files are useful. If you have many sites on a remote server, instead of manually adding them to your alias file every time, write some code to automatically generate them.

[php title=”~/.drush/dynamic.aliases.drushrc.php”]
$domains = explode(“\n”, trim(shell_exec(“ssh user@myserver.example.com ‘ls /some/path'”)));
// now $domains is a list of directories on your remote server

// set up an alias for each one
foreach ($domains as $domain) {
$aliases[$domain] = array(
‘root’ => “/path/to/$domain/public_html”,
‘remote-host’ => ‘some-server.com’,
// if necessary, URI other than default
‘uri’ => $domain,
‘remote-user’ => ‘user_if_necessary’,
);
}
[/php]

Now whenever a site is configured on your target server, you will automatically have the alias!