Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用以下代码在另一台机器上启动命令:
#!/bin/bash /usr/bin/rsh -n $Host_Name "cat asdf.txt &"
我正在尝试使用以下命令获取 cat 命令的 PID:
/usr/bin/rsh -n $Host_Name pid="$!"
但是当我回显 $pid 时,它只是空白。我做错了什么?有没有更简单的方法来获取在另一台机器上执行的最后一个命令的 PID?
谢谢
你只能得到$!您在其中启动命令的 shell 中的后台命令。如果您的命令没有向 stderr 输出任何内容,这可能有效:
/usr/bin/rsh -n $Host_Name "cat asdf.txt & echo $! >&2" 2> pidfile
启动命令的 pid 然后将本地存储在“pidfile”中。
只是一个旁注:我永远不会使用 rsh。它本质上是不安全的。我会改用 ssh ;)