在Expect脚本中处理多个Spawn进程 [英] Handle multiple Spawn process in expect script
本文介绍了在Expect脚本中处理多个Spawn进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的Expect脚本用例(我有几个用例之一)
Here is my use case for expect script ( one of few i have)
我想通过ssh运行多个sed
命令.就像构建前的环境设置一样.
我想运行这样的东西:-
I want to run multiple sed
command over ssh. Its like pre-build environment setup.
I want to run something like this :-
#!/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
命令.第一个和第二个将被跳过.
But only last sed
command will execute. 1st and 2nd will be skipped.
我想念的隐藏的宝石是什么?
What could be the hidden gem i am missing?
这是我到目前为止所看到的,但没有帮助
Here is what i looked at so far but not helpful
推荐答案
在这里您真的不需要 multiple (意味着 parallel )spawn
.
You don't really need 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)\"
exp_continue
}
eof { wait } ; # at this time the last spawn'ed process has exited
}
}
这篇关于在Expect脚本中处理多个Spawn进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文