gpt4 book ai didi

bash - 远程获取在后台启动的作业的 pid

转载 作者:行者123 更新时间:2023-11-29 09:05:14 25 4
gpt4 key购买 nike

我正在尝试在后台启动远程机器上的作业并获取其 PID,以便稍后可以将其终止。到目前为止,我得出的结论如下:

#!/bin/bash

IP=xxx.xxx.xxx.xx
REMOTE_EXEC="ssh $IP -l root"

# The following does NOT work, I am trying to get the PID of the remote job
PID=`$REMOTE_EXEC 'vmstat 1 1000 > vmstat.log & ; echo $!'`

# Launch apache benchmark
ab -n 10 http://$IP/

$REMOTE_EXEC "kill $PID"

不幸的是,它不起作用。我得到一个

bash: syntax error near unexpected token `;'

但我不知道正确的语法是什么。

最佳答案

你得到了错误,因为你 ';'是多余的,试试 'vmstat 1 1000 > vmstat.log & echo $!'

但我不确定它是否会起作用,因为在您注销后,该进程将收到 SIGHUP。看看 nohup(1)。

关于bash - 远程获取在后台启动的作业的 pid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1043323/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com