I have written a small bash script which needs an ssh tunnel to draw data from a remote server, so it prompts the user:
echo "Please open an ssh tunnel using 'ssh -L 6000:localhost:5432 example.com'"
I would like to check whether the user had opened this tunnel, and exit with an error message if no tunnel exist. Is there any way to query the ssh
tunnel, i.e. check if the local port 6000 is really tunneled to that server?
Autossh is best option - checking process is not working in all cases (e.g. zombie process, network related problems)
example:
This is my test. Hope it is useful.
Netcat is your friend: