[macos] check exit code in Invoke-SSHPassCommand (#8156)

This commit is contained in:
ilia-shipitsin
2023-08-25 11:29:01 +02:00
committed by GitHub
parent b21ec054ff
commit a4f3c433b4
3 changed files with 13 additions and 3 deletions

View File

@@ -67,7 +67,7 @@ function Invoke-AnkaCommand {
[string] $Command
)
$result = bash -c "$Command 2>&1" | Out-String
$result = bash -c "$Command 2>&1"
if ($LASTEXITCODE -ne 0) {
Write-Error "There is an error during command execution:`n$result"
exit 1

View File

@@ -45,6 +45,8 @@ function Invoke-EnableAutoLogon {
$ipAddress = Get-AnkaVMIPAddress -VMName $TemplateName
Wait-AnkaVMSSHService -VMName $TemplateName -Seconds 30
Write-Host "`t[*] Enable AutoLogon"
Enable-AutoLogon -HostName $ipAddress -UserName $TemplateUsername -Password $TemplatePassword

View File

@@ -292,7 +292,12 @@ function Invoke-SSHPassCommand {
"${env:SSHUSER}@${HostName}"
)
$sshPassOptions = $sshArg -join " "
bash -c "$sshPassOptions \""$Command\"" 2>&1"
$result = bash -c "$sshPassOptions \""$Command\"" 2>&1"
if ($LASTEXITCODE -ne 0) {
Write-Error "There is an error during command execution:`n$result"
exit 1
}
$result
}
function Invoke-WithRetry {
@@ -330,7 +335,10 @@ function Restart-VMSSH {
[string] $HostName
)
$command = "sudo reboot"
#
# https://unix.stackexchange.com/questions/58271/closing-connection-after-executing-reboot-using-ssh-command
#
$command = '(sleep 1 && sudo reboot &) && exit'
Invoke-SSHPassCommand -HostName $HostName -Command $command
}