I'm currently writing a Bash script that creates an SSH tunnel. Once this is done, I would like the script to open a new local (!) interactive shell so that I can work on my system with the SSH tunnel open.
Once I type exit
the local shell should be closed, and the original script continues to run.
My current approach basically looks like this:
#!/usr/bin/env bash
set -e
ssh -N user@ip -L xxx:xxx &
SSH_CONNECTION=${!}
trap "kill ${SSH_CONNECTION}" ERR
sleep 3
bash -i
kill ${SSH_CONNECTION}
So far, everything works - except running the local shell. I actually get a shell, and I can even type in it, but nothing happens when I hit <Return>
.
Any idea what I'm doing wrong?
trap
's signalERR
? AFAIK it doesn't exist. (Proof:/bin/kill -L
) – Alex Feb 1 '17 at 10:08bash
ism, sorry, missed that, ignore previous then – Alex Feb 2 '17 at 9:00