#!/bin/sh
# $REMOTE_HOST is the name of the remote system
REMOTE_HOST=firewall
# $REMOTE_PORT is the remote port number that will be used to tunnel
# back to this system
REMOTE_PORT=22222
# $COMMAND is the command used to create the reverse ssh tunnel
COMMAND="ssh -q -N -R $REMOTE_PORT:localhost:22 $REMOTE_HOST"
# Is the tunnel up? Perform two tests:
# 1. Check for relevant process ($COMMAND)
pgrep -f -x "$COMMAND" > /dev/null 2>&1 || $COMMAND
# 2. Test tunnel by looking at "netstat" output on $REMOTE_HOST
ssh $REMOTE_HOST netstat -an | egrep "tcp.*:$REMOTE_PORT.*LISTEN" >
/dev/null 2>&1
if [ $? -ne 0 ] ; then
pkill -f -x "$COMMAND"
$COMMAND
fi
~$ crontab -e
# m h dom mon dow command
*/17 * * * * ~/bin/ssh-r.sh
Nenhum comentário:
Postar um comentário