加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

bash – 远程启动后台启动作业的pid

发布时间:2020-12-15 21:39:52 所属栏目:安全 来源:网络整理
导读:我试图在后台启动一个远程机器上的工作并获得它的PID,以便我可以在以后杀死它.到目前为止我想出的是以下内容: #!/bin/bashIP=xxx.xxx.xxx.xxREMOTE_EXEC="ssh $IP -l root"# The following does NOT work,I am trying to get the PID of the remote jobPID=
我试图在后台启动一个远程机器上的工作并获得它的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).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读