Use --ssh=<host>[:<path>] to run commands on remote servers#2755
Conversation
| WP_CLI::debug( 'SSH path: ' . $path, 'bootstrap' ); | ||
|
|
||
| $is_tty = function_exists( 'posix_isatty' ) && posix_isatty( STDOUT ); | ||
|
|
There was a problem hiding this comment.
@westonruter @jonathanbardo In situations where wp is defined by an alias or addition to PATH in a .bash_profile, have you found a way to load this?
There was a problem hiding this comment.
/usr/bin/env wp ?
I haven't tested yet. 😄
There was a problem hiding this comment.
@danielbachhuber That's a valid scenario and I don't think we ever faced that problematic while we developed wp-cli-ssh.
There was a problem hiding this comment.
Hm, not quite:
local ➜ wp-cli git:(2754-ssh) ✗ wp --ssh=hb
/usr/bin/env: wp: No such file or directory
There was a problem hiding this comment.
That's a valid scenario and I don't think we ever faced that problematic while we developed wp-cli-ssh.
Unfortunately, it's a problem with the first server I tested with :(
There was a problem hiding this comment.
Ah it looks difficult.
- Place the
~/.ssh/environmentinto local machine. - Add
PermitUserEnvironment yesin/etc/ssh/sshd_configon remote server.
There was a problem hiding this comment.
@danielbachhuber This is why there was recent support for a wpcli_command config to handle situations where wp isn't on the PATH: xwp/wp-cli-ssh#27
There was a problem hiding this comment.
This is why there was recent support for a wpcli_command config to handle situations where wp isn't on the PATH: xwp/wp-cli-ssh#27
@westonruter Did you explore trying to get the data out of .bash_profile ? I'd prefer to not have to institute a workaround...
There was a problem hiding this comment.
No, I didn't. Also, perhaps the PHAR isn't even aliased as wp on the target environment. I think that there will ultimately need to be a way to provide an alternate path.
There was a problem hiding this comment.
No, I didn't. Also, perhaps the PHAR isn't even aliased as wp on the target environment. I think that there will ultimately need to be a way to provide an alternate path.
I ended up creating a WP_CLI_PRE_SSH_CMD env variable, to offer a bit more flexibility:
WP_CLI::add_hook( 'before_ssh', function() {
if ( $ssh = WP_CLI::get_runner()->config['ssh'] ) {
list( $host, $path ) = explode( ':', $ssh );
switch( $host ) {
case 'hb':
putenv( 'WP_CLI_SSH_PRE_CMD=export PATH=$HOME/bin:$PATH' );
break;
}
}
});
|
I'm not sure I see the difference between |
This PR is the first part of #2039. Think There's not much difference between |
```
WP_CLI::add_hook( 'before_ssh', function() {
if ( $ssh = WP_CLI::get_runner()->config['ssh'] ) {
list( $host, $path ) = explode( ':', $ssh );
switch( $host ) {
case 'hb':
putenv( 'WP_CLI_SSH_PRE_CMD=export PATH=$HOME/bin:$PATH' );
break;
}
}
});
```
See #2754