Problem
I call a long running process via ssh. And it's necessary that this process will not be killed. The user may kill the initial process on its host and I cannot do anything about it.
How to make the remote process not be killed if the initial process gets killed?
User -> user.sh -> SSH-to-remote -> long-running.sh
It must:
- Output the output of the remoteprocess
- Exit when the remote process exits
- Don't kill the remote process, wenn the initial process gets killed
- Make an output log file available
First incomplete solution
I thought about something using nohup but it didn't work so far:
User -> user.sh -> SSH-to-remote -> init.sh -> long-running.sh
init.sh
#!/bin/bash
nohup ./long-running.sh >out.log 2>&1 </dev/null &
pid=$!
disown $pid
tail -f out.log &
wait $pid
long-running.sh (content for testing)
#!/bin/bash
for i in $(seq 30)
do
echo $i
sleep 1
done
This solution doesn't solve 2. It doesn't exit when the remote process exits.