I'm running a script with ssh commands to a server behind a jump-host. Each time I want to run a command on my server in the secure network, I need to ssh into the jump-host (bastion) server and run
nc and then ssh in with the actual command I want to run through the netcat channel. Then I need to stop the original
I'd like a 'smart ampersand' that lets me run both processes at the same time, and then shuts down the
nc ssh process when my piggie-backed process is completed.
Here is what I'm doing currently.
ssh -g -L 23:localhost:22 -f -N user@jumphost & ssh user2@localhost -P 23 "ssh user@destination server \"ls -al\"" kill -0 $!
The problem with this is that it is not atomic. If there is an error in the script, then it doesn't complete and I don't kill the original
nc process at the end.
My question is: How to start two processes piggie-backed? So the first finishes when the second finishes?