I am a novice Linux user, and also completely new to ssh and tunnels.
In any case, my goal is to keep the ssh tunnel open in the background.
To do this, I wrote the following batch, which I then added to crontab (the package is automatically processed every 5 minutes on weekdays and from 8 am to 9 pm). I read in some other thread in stackoverflow that should use autossh, which will ensure that ssh will always be ok with periodic checking. I, too...
#!/bin/bash LOGFILE="/root/Tunnel/logBatchRestart.log" NOW="$(date +%d/%m/%Y' - '%H:%M)" # date & time of log if ! ps ax | grep ssh | grep tunnelToto &> /dev/null then echo "[$NOW] ssh tunnel not running : restarting it" >> $LOGFILE autossh -f -N -L pppp:tunnelToto:nnnnn nom-prenom@193.xxx.yyy.zzz -p qqqq if ! ps ax | grep ssh | grep toto &> /dev/null then echo "[$NOW] failed starting tunnel" >> $LOGFILE else echo "[$NOW] restart successfull" >> $LOGFILE fi fi
My problem is that sometimes the tunnel stops working, although everything looks fine (ps ax | grep ssh> the result shows two expected tasks: the main task is autossh and the ssh tunnel itself). I really know about the problem, because the tunnel is used by third-party software, which causes an error as soon as the tunnel no longer responds.
SO I wonder how I should improve my party in order. He will be able to check the tunnel and restart it if he is dead. I saw some ideas in there , but this was completed with the "autossh" hint ... which I already use. So I have no ideas ... If any of you have, I would love to look at them!
Thank you for your interest in my question and for your (possibly) suggestions!
source share