sh /root/uptime_monitor.sh & while [ 1 ] do if nc -zv -w 2 88.202.151.14 5222 &> /dev/null then echo "$(date): success" echo "$(date): now check whether PID is present (as might be old connection)" else echo "$(date): error - xmpp is down, start tunnel 5222" /usr/bin/ssh -R '*:5222:127.0.0.1:5222' -p 22 -N user@88.202.151.14 & sleep 2 fi if nc -zv -w 2 88.202.151.14 5269 &> /dev/null then echo "$(date): success" echo "$(date): now check whether PID is present (as might be old connection)" else echo "$(date): error - xmpp is down, start tunnel 5269" /usr/bin/ssh -R '*:5269:127.0.0.1:5269' -p 22 -N user@88.202.151.14 & sleep 2 fi sleep 60 done echo "$(date): Done"