这是我的预期脚本的用例(我拥有的少数几个之一)
我想运行多个sed
通过 ssh 命令。它就像预构建环境设置一样。
我想运行这样的东西:-
#!/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
命令将执行。第 1 条和第 2 条将被跳过。
我错过的隐藏宝石可能是什么?
这是我到目前为止所看到的,但没有帮助
- 处理expect脚本中的多个语句
- Expect脚本:如何处理两个进程?
- 同时处理多个进程 - Safari 在线图书
你真的不需要multiple (means parallel) spawn
here.
#!/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)\r"
exp_continue
}
eof { wait } ; # at this time the last spawn'ed process has exited
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)