public function runCommand($command)
{
// vet our input
Contract::RequiresValue($command, is_string($command));
Contract::RequiresValue($command, !empty($command));
// make the params printable / executable
// $printableParams = $this->convertParamsForUse($params);
// what are we doing?
$log = usingLog()->startAction("run command '{$command}' against host ");
// do we actually have everything we need to run the command?
if (!$this->hasSshUsername()) {
throw new E4xx_NeedSshUsername();
}
if (!$this->hasIpAddress()) {
throw new E4xx_NeedIpAddress();
}
// build the full command
//
// the options that we pass (by default) to SSH:
//
// -o StrictHostKeyChecking=no
// do not verify the SSH host key (avoids an interactive prompt)
// -i <private_key>
// use specified private key to access the remote/guest OS
// <username>@<hostname>
// who we are logging in as (should never be root)
// <additional SSH options>
// any other flags, such as -n to force non-interactive session
// <command> <command-args>
// the command to run on the remote/guest OS
// (assumes the command will be globbed by the remote shell)
$fullCommand = 'ssh ' . ' ' . $this->getSshKeyForUse() . ' ' . $this->getSshOptionsForUse() . ' ' . $this->getSshUsername() . '@' . $this->getIpAddress() . ' "' . str_replace('"', '\\"', $command) . '"';
// run the command
//$log->startStep("run command via SSH: {$fullCommand}");
$commandRunner = $this->st->getNewCommandRunner();
$result = $commandRunner->runSilently($fullCommand);
//$log->endStep();
// all done
$log->endAction("return code was '{$result->returnCode}'");
return $result;
}