我正在尝试对多个服务器异步运行多个 SSH 命令,我想捕获命令的输出并按顺序显示它们。要添加一个额外的曲线球,我希望 pid3 仅在 pid2 完成后运行,而 pid4 在前三个命令完成后运行。这将如何最好地完成?
例子:
// $pid1 and $pid2 should run asynchronously
my $pid1 = open(my $SSH1, "|ssh -t -t runuser\@$server{'app'} 'sudo chef-client'");
my $pid2 = open(my $SSH2, "|ssh -t -t runuser\@$server{'auth'} 'sudo chef-client'");
// This command should wait for $pid2 to complete.
my $pid3 = open(my $SSH3, "|ssh -t -t runuser\@$server{'auth'} \"sudo -- sh -c '$update_commands'\"");
// This command should wait for $pid1-3 to complete before running.
my $pid4 = open(my $SSH4, "|ssh -t -t runuser\@$server{'varn'} \"sudo -- sh -c '$varn_commands'\"");