[英]Handle multiple Spawn process in expect script
这是我的期望脚本的用例(我拥有的少数几个)
我想在ssh上运行多个sed
命令。 就像构建前的环境设置一样。 我想运行这样的东西:
#!/usr/bin/expect
set timeout -1
spawn -noecho bash -c "ssh -t user@host 'sed -i <some_stuff1> <file1>'"
spawn -noecho bash -c "ssh -t user@host 'sed -i <some_stuff2> <file2>'"
spawn -noecho bash -c "ssh -t user@host 'sed -i <some_stuff3> <file3>'"
expect {
-re ".*sword.*" {
exp_send "$env(PASS_WORD)\n"
exp_continue
}
}
但是只有最后的sed
命令会执行。 第一和第二将被跳过。
我想念的隐藏的宝石是什么?
这是我到目前为止所看到的,但没有帮助
您实际上并不需要在这里spawn
多个 (意味着并行 )。
#!/usr/bin/expect
set timeout 60
set cmds [list "ssh host1 ..." "ssh host2 ..." "ssh host3 ..."]
foreach cmd $cmds {
spawn -noecho bash -c $cmd
expect {
-nocase "password" {
exp_send "$env(PASS_WORD)\"
exp_continue
}
eof { wait } ; # at this time the last spawn'ed process has exited
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.