I am struggling with writing what I assume should be an easy script.
Basically I have a computer at work, which is hidden behind a NAT to which I don't have access. I need to SSH into this computer, so the only way to do this is to set a reverse port redirect, where this NATted computer will connect to my server at home, while redirecting a port for it self and then I can simply ssh into it through my home server.
The .sh script will be executed by the computer at work every 5 minutes and this is what I would like it to do:
Check if there is an active ssh connection to my server going on and if yes, then simply do nothing and exit the script.
If there is no active connection detected, then connect by executing "ssh me@1.2.3.4 -i key.priv" and exit the script.
If the ssh connection attempt hangs for some reason, for say longer than 2 minutes, then force exit the script (not sure if this is possible to do, if not, then it doesn't have to be there)
Thank you kindly for your advice.
autossh
is already available :) Please review this answer: https://askubuntu.com/a/1006245/566421 – pa4080 Apr 26 '18 at 09:52