fix: use batch file for port-forward SSH commands to avoid quote escaping issues

This commit is contained in:
Reditus committed 2026-05-14 06:02:23 +01:00
1 parent 6a166b8ac0
commit 8a061fa8e6
1 file changed
+6 -6
+6 -6
View File
@@ -177,9 +177,9 @@ if ($pfCheck) {
$RemotePort = 15432 $RemotePort = 15432
$remoteCmd = 'nohup sudo kubectl port-forward -n ' + $Namespace + ' svc/' + $DBService + ' ' + $LocalPort + ':' + $RemotePort + ' > /tmp/pf.log 2>&1 &' $remoteCmd = 'nohup sudo kubectl port-forward -n ' + $Namespace + ' svc/' + $DBService + ' ' + $LocalPort + ':' + $RemotePort + ' > /tmp/pf.log 2>&1 &'
$remoteCmdEscaped = $remoteCmd -replace '&', '`&' $pfRemote = 'ssh -i "' + $SSHKey + '" -o StrictHostKeyChecking=accept-new -o ServerAliveInterval=30 ' + $SSHUser + '@' + $ServerHost + ' "' + $remoteCmd + '"'
$pfRemote = 'ssh -i "' + $SSHKey + '" -o StrictHostKeyChecking=accept-new -o ServerAliveInterval=30 ' + $SSHUser + '@' + $ServerHost + ' "' + $remoteCmdEscaped + '"' $pfRemote | Out-File -FilePath "$env:TEMP\ssh_pf_db.bat" -Encoding ascii
cmd /c $pfRemote cmd /c "$env:TEMP\ssh_pf_db.bat"
$bgdSvc = "${Namespace}-bgd-svc" $bgdSvc = "${Namespace}-bgd-svc"
$pfCheckBgd = ssh -i $SSHKey -o StrictHostKeyChecking=accept-new -o ConnectTimeout=10 ${SSHUser}@${ServerHost} "sudo kubectl get svc -n ${Namespace} -o name" 2>$null $pfCheckBgd = ssh -i $SSHKey -o StrictHostKeyChecking=accept-new -o ConnectTimeout=10 ${SSHUser}@${ServerHost} "sudo kubectl get svc -n ${Namespace} -o name" 2>$null
@@ -190,9 +190,9 @@ if ($pfCheckBgd) {
$directorRemotePort = 11717 $directorRemotePort = 11717
$directorCmd = 'nohup sudo kubectl port-forward -n ' + $Namespace + ' svc/' + $bgdSvc + ' ' + $DirectorPort + ':' + $directorRemotePort + ' > /tmp/director_pf.log 2>&1 &' $directorCmd = 'nohup sudo kubectl port-forward -n ' + $Namespace + ' svc/' + $bgdSvc + ' ' + $DirectorPort + ':' + $directorRemotePort + ' > /tmp/director_pf.log 2>&1 &'
$directorCmdEscaped = $directorCmd -replace '&', '`&' $directorPf = 'ssh -i "' + $SSHKey + '" -o StrictHostKeyChecking=accept-new -o ServerAliveInterval=30 ' + $SSHUser + '@' + $ServerHost + ' "' + $directorCmd + '"'
$directorPf = 'ssh -i "' + $SSHKey + '" -o StrictHostKeyChecking=accept-new -o ServerAliveInterval=30 ' + $SSHUser + '@' + $ServerHost + ' "' + $directorCmdEscaped + '"' $directorPf | Out-File -FilePath "$env:TEMP\ssh_pf_director.bat" -Encoding ascii
cmd /c $directorPf cmd /c "$env:TEMP\ssh_pf_director.bat"
Start-Sleep -Seconds 3 Start-Sleep -Seconds 3