【发布时间】:2018-04-19 23:03:25
【问题描述】:
试图从linux机器执行expect脚本来捕获放置在windows机器中的powershell脚本的返回码。
run.sh
expect ssh.exp $USER $HOST $PASSWD "PowerShell -NonInteractive -NoProfile -Command test.ps1"
ssh.exp
#!/usr/bin/expect
set user [lindex $argv 0];
set host [lindex $argv 1];
set pass [lindex $argv 2];
set cmd [lindex $argv 3];
spawn ssh -C -oStrictHostKeyChecking=no -oCheckHostIP=no $user@$host
expect "password:"
send "$pass\r"
expect -re ".*?>"
send "$cmd\r"
expect -re ".*?>"
send "exit\r"
interact
test.ps1
function test {
$i = 1
if ($i -eq 2) {
Write-Host "success"
}
else {
Write-Host "failed"
$host.SetShouldExit(5)
exit
}
}
Write-Host "Exiting with code 5"
test
预期返回码:5
【问题讨论】:
-
不要像这样扔代码,你应该解释你的3个代码来改进可能的答案
标签: linux shell powershell ssh expect