Run application if and only if SSH Tunneling is active on port X
I am running a code-server on my remote Ubuntu machine and right now my method for starting it up is to
ssh -t -t user@server "code-server"on one terminal (the
-t -tI got from this)
ssh -N -L 8443:127.0.0.1:8443 user@serveron a second terminal
- Open the application on the browser
Then when I want to close it, I just close both terminals. My question is if would be possible to do this using only one connection, currently I have to authenticate twice because this requires two ssh sessions, one for starting the application and sending the KILL when closed and another one for the tunneling.
I’ve tested the following and it seems to work:
ssh -t -t -L 8443:localhost:8443 user@server "sleep 3" Connection to server closed.
it waits for 3 seconds and then closes the SSH session. I’d say you can put your application in the quotes instead of
sleep 3 or remove the whole
"sleep 3" and that would give you interactive shell.