リモートプロセスを非同期で実行し、そのリモート pid、出力 (stdout + stderr) をファイルまたは変数 (さらに処理するために必要) に保存し、コードを終了したいと考えています。
リモート pid は、リモート プロセスが完了した後ではなく、実行中に必要になります。また、同じ名前の複数のプロセスがリモート マシンで実行されるため、プロセス名を使用するソリューションは機能しません。
私がこれまでに持っているもの:
export SSH="ssh -o ServerAliveInterval=100 $user@$remote_ip"
「my_test」は実行したいバイナリです。
私が試したリモートpidと出力を取得するには:
$SSH "./my_test > my_test_output & echo \$! > pid_file"
remote_pid=$($SSH "cat pid_file")
# run some remote application which needs the remote pid (send signals to my_test)
$SSH "./some_tester $remote_pid"
# now wait for my_test to end and get its exit code
$SSH "wait $remote_pid; echo $?"
bash: wait: pid 71033 is not a child of this shell
$SSH コマンドは、この ssh ソケット ( https://unix.stackexchange.com/a/30433/316062 )に接続されているファイル記述子がないため、リモート pid を pid_file にエコーした後に戻ります。
どうにか my_test 終了コードを取得する方法はありますか?