在 expect 脚本中处理多个 Spawn 进程
Handle multiple Spawn process in expect script
这是我的 expect 脚本用例(我拥有的少数脚本之一)
我想通过 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
命令。第一和第二将被跳过。
我遗漏的 gem 可能是什么?
这是我目前看过但没有帮助的内容
Handle multiple statement in expect script
Expect script: How to handle two processes?
Handling multiple process simuntaneously - safari online book
你真的不需要 multiple(意思是 parallel)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)\r"
exp_continue
}
eof { wait } ; # at this time the last spawn'ed process has exited
}
}
这是我的 expect 脚本用例(我拥有的少数脚本之一)
我想通过 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
命令。第一和第二将被跳过。
我遗漏的 gem 可能是什么?
这是我目前看过但没有帮助的内容
Handle multiple statement in expect script
Expect script: How to handle two processes?
Handling multiple process simuntaneously - safari online book
你真的不需要 multiple(意思是 parallel)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)\r"
exp_continue
}
eof { wait } ; # at this time the last spawn'ed process has exited
}
}