I'm trying to write reverse ssh tunneling, but for some reason it doesn't run well !
If Someone know how to make right this sort of script, please help !
Thanks a lot !

#!/bin/sh
REMOTE_HOST='the remote host'
PASS='the remote password'
REMOTE_PORT=5000
# $COMMAND is the command used to create the reverse ssh tunnel
COMMAND="ssh -q -N -R $REMOTE_PORT:localhost:22 the-remote-username@$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
Users browsing this forum: No registered users and 0 guests