Skip to content

Instantly share code, notes, and snippets.

@isheev
Last active May 19, 2021 06:49
Show Gist options
  • Save isheev/755f5c0e2309e3eda08648c30b0d6114 to your computer and use it in GitHub Desktop.
Save isheev/755f5c0e2309e3eda08648c30b0d6114 to your computer and use it in GitHub Desktop.
Start ssh tunnel for CRON
#!/bin/bash
SSH_USER="user"
SSH_SERVER_IP="server"
REDIRECT_PORT_FROM=234567
REDIRECT_PORT_TO=22
pgrep -f $REDIRECT_PORT_FROM:localhost || ssh -R $REDIRECT_PORT_FROM:localhost:REDIRECT_PORT_TO $SSH_USER@$SSH_SERVER_IP -N -f
#Add to CRON for running every minute
#* * * * * sh $HOME/start_ssh_tunnel.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment