I'm using autossh to connect to a reverse SSH tunnel. I run it from startup.
However, I was facing problems in that the tunnel sometimes goes down.
I created a script which checks if the tunnel is actually working , and if not do other stuff like restart the modem.
The only way I seem to be able to check if the tunnel is working is by using the autossh command again and checking the reply.
autossh -M 0 -N -q -o ServerAliveInterval=20 -o ServerAliveCountMax=3 HMzg8fYGfW11oJ7Jl6BCTT2lYrB@fw1.sshreach.me -i id_rsa -R 13212:localhost:22 -v
I just noticed tho that every time I use this autossh command, it starts a new auto process. There are so many autossh processes running now. This is obviously not good.
There are two questions :
1) Is there a better way to verify if my tunnel is working without using the autossh command again? (I couldn't find another way)
2) The other option I suppose is to kill the processes in my script which are not used and just have the one autossh process. However, How do I find the pid of a process if there are many of them with the name autossh?
Thanks in advance
autosshshould reconnect but if the server doesn't notice the old connection is no more, it won't release the port binding, so the new one won't re-establish the tunnel. InvestigateExitOnForwardFailure=yesand see this: Disable port forward remotely…. This is not an answer because (1) it doesn't answer the explicit questions, (2) I'm not sure I identified your problem right. – Kamil Maciorowski Feb 17 '19 at 00:20sshis terminated and there is no way to notify the server this particular SSH connection is no more". For now your problem seems very similar. Do you runautosshwith-for&, or with cron every minute? Don't. Don't run the next one unless the current one exits. Make sure it exits when it should,ExitOnForwardFailure=yesis the right approach. Have you already tried what my answer says? If it doesn't help, please [edit] the question and describe exactly what you do/tried and what response you get. – Kamil Maciorowski Feb 17 '19 at 17:52-voption), etc. I expect it does connect and does nothing (because of-N); but the tunnel is not re-established because the port is in use by the old connection the server thinks is still valid. Instead of worrying in advance and explaining what you think will happen, or discuss "if it doesn't work", just apply my answer first. Then, if it really doesn't work, post ([edit]) exact commands, logs and messages. – Kamil Maciorowski Feb 17 '19 at 19:46