I am using the Symfony 4 Process component to run various ssh commands. This all worked last fall and fails now.
The examples here are all real code (except for the remote host and username). This is the baseline:
<?php
namespace App\Command;
use ...
class TestCommand extends Command
{
public static $defaultName = 'app:test';
public function configure()
{
$this->setDescription( 'Test command for Process problem' );
}
protected function execute( InputInterface $input, OutputInterface $output )
{
$host = 'dpatterson@webhost01.dplhenterprises.com';
$command =
[
// Command, arguments, and options.
];
$process = new Process( $command );
$process->run();
$output->writeln( 'Output: ' . $process->getOutput());
$output->writeln( 'Errors: ' . $process->getErrorOutput());
}
}
For the remainder of this post I'll present the value of $command and the output.
$command as command and argument together:
$command = ['/usr/bin/ssh ' . $host . ' "if [ -d /admin ]; then echo 1; else echo 0; fi"'];
Output:
Errors: sh: /usr/bin/ssh user@example.com "if [ -d /admin ]; then echo 1; else echo 0; fi": No such file or directory
sh: line 0: exec: /usr/bin/ssh user@example,com "if [ -d /admin ]; then echo 1; else echo 0; fi": cannot execute: No such file or directory
$command is separate command and argument:
$command =
[
'/usr/bin/ssh',
$host . ' "if [ -d /admin ]; then echo 1; else echo 0; fi"',
];
The process "'/usr/bin/ssh' 'user@example.com "if [ -d /admin ]; then echo 1; else echo 0; fi"'" exceeded the timeout of 60 seconds.
$command as three separate items:
$command =
[
'ssh',
$host,
'"if [ -d /admin ]; then echo 1; else echo 0; fi"',
];
Output:
Errors: bash: if [ -d /admin ]; then echo 1; else echo 0; fi: No such file or directory
Again, this worked with the first configuration in the fall of 2018. I honestly don't know what version of Symfony I was using at the time, but I'm pretty sure it was at least 4.1.
Environment:
- macOS High Sierra 10.13.6
- PHP: 7.2.14
- Symfony 4.2.2
TIA