Enhance SSH execution in VsphereHostSshService to capture stdout and stderr; improve error handling for command execution
This commit is contained in:
@@ -247,14 +247,28 @@ final class VsphereHostSshService
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$output = $client->exec($remoteCmd);
|
$stdout = $client->exec($remoteCmd);
|
||||||
|
$stderr = $client->getStdError();
|
||||||
|
|
||||||
Log::info('VsphereHostSshService: SSH executed', [
|
Log::info('VsphereHostSshService: SSH executed', [
|
||||||
'host' => $config['host'],
|
'host' => $config['host'],
|
||||||
'port' => $config['port'],
|
'port' => $config['port'],
|
||||||
|
'stdout' => trim((string) $stdout),
|
||||||
|
'stderr' => trim((string) $stderr),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return (string) $output;
|
if ($stdout === false) {
|
||||||
|
throw new \RuntimeException(
|
||||||
|
"SSH exec failed on {$config['host']}:{$config['port']}. stderr: " . trim((string) $stderr)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Windows SSH servers sometimes write script output to stderr instead of stdout
|
||||||
|
if (trim($stdout) === '' && trim((string) $stderr) !== '') {
|
||||||
|
return (string) $stderr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (string) $stdout;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user