如果我在Bash中执行以下操作,那么我将获得远程启动的PID mbuffer
,即使mbuffer
仍在运行,也可以将终端取回,这正是我想要的。
read -r pid < <(ssh 10.10.10.47 'nohup /opt/omni/bin/mbuffer -4 -s 128k -m 2G -v 0 -q -I 8023 >/tmp/mtest </dev/null 2>/tmp/mtest.err & echo $!')
echo $pid
现在我想在Perl中做同样的事情,所以我尝试
use Capture::Tiny 'capture';
my ($stdout, $stderr, $exit) = capture {
system("read -r pid < <(ssh 10.10.10.47 'nohup /opt/omni/bin/mbuffer -4 -s 128k -m 2G -v 0 -q -I 8023 >/tmp/mtest </dev/null 2>/tmp/mtest.err & echo $!'); echo \$pid");
};
print "stdout $stdout\n";
print "stderr $stderr\n";
print "exit $exit\n";
在这里,我本来希望$stdout
可以从上一条echo
命令中获得PID ,但是却一无所获。
题
如何获得mbuffer
在Perl中远程执行的PID,以使Perl脚本mbuffer
在继续之前不等待退出?
问题似乎是不可能一次执行两个命令,system()
或者不可能一次执行两个命令,但是不可能从最后一个命令获得输出。
创建本地帮助程序脚本解决了该问题。
#!/usr/bin/bash
# Redirection of stdin and stderr to files (preventing them from holding
# handles that connect, eventually, to the terminal).
read -r pid < <(ssh $1 "/usr/gnu/bin/nohup /opt/omni/bin/mbuffer -4 -s 128k -m 2G -v 0 -q -I 8023 >/tmp/mtest$2 </dev/null 2>/tmp/mtest.err & echo \$!")
echo $pid
而在Perl中
my ($stdout, $stderr, $exit) = capture {
system("/comp/mbuffer-zfs-listen.sh 10.10.10.47 11");
};
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句