Run command before starting a tunnel


I want to run below command everytime before starting my remote tunnel, something like:

$ ssh zuser@ -p 22 -t 'kill -9 $(sudo lsof -ti tcp:9000)'

to kill all the processes listening on port 9000 on the remote server Is there any way to achieve this in core tunnel ?

Unfortunately, it is not possible at this moment. This requires Core Tunnel removes "-T" and "-N" options, I have to do some test deliberately before removing "-TN". Will update this thread once we find a solution.

1 Like

Core Tunnel version 1.7 now can execute you command by setting RemoteCommand to:

bash --init-file <(kill -9 $(lsof -ti tcp:9000))

You may notice I removed sudo from the command on purpose, since Core Tunnel do not have a terminal window like Core Shell, so it could not react to password input which sudo would require.

bash --init-file < prefix makes sure the tunnel can persists after command is executed, otherwise, the connection will be disconnected immediately afterward.

1 Like

Thanks @yang for making this possible. Would surely try this out.