【发布时间】:2023-03-18 04:30:02
【问题描述】:
我有一个 bash 脚本,它需要在远程机器上启动一些进程。
我已经使用sshpass 命令完成了。
我需要存储那个远程进程的 PID。
我用脚本尝试了以下操作:
sshpass -p password ssh user@ipaddr /bin/bash << EOF
nohup process > /dev/null 2>&1 & echo $! > pid_file
cat pid_file
EOF
当我检查远程机器时,该进程已启动,并且 pid_file 中也写入了一个数字。但是进程id和pid_file个数不匹配。
在没有脚本的情况下直接在终端上执行上述命令集,不会在 pid_file 中写入任何内容。
有人可以帮助存储远程进程的正确 pid。
【问题讨论】:
-
也许执行
nohup process 2&1>pid_file会给你更多信息。 -
这样卡住了。我必须在后台运行进程“iperf3”。