Created
August 9, 2011 22:01
-
-
Save offlinehacker/1135311 to your computer and use it in GitHub Desktop.
Persistent ssh tunnel.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [ $# -ne 1 ] | |
then | |
echo "Syntax: `basename $0` [email protected]" | |
exit | |
fi | |
IP=$1 | |
cmd="ssh $IP -f -n /bin/ping -i 20 localhost" | |
program_exists() { | |
if pidof $1 > /dev/null; then | |
for p in $(pidof $1) | |
do | |
cmdline=$(cat /proc/"$p"/cmdline | xargs -0) | |
if [ "$cmdline" == "$cmd" ]; then | |
return 1 | |
fi | |
done | |
fi | |
return 0 | |
} | |
start() { | |
program_exists ssh | |
if [ $? -eq 0 ]; then | |
eval "$cmd > /dev/null" | |
fi | |
} | |
stop() { | |
if pidof ssh > /dev/null; then | |
for p in $(pidof ssh) | |
do | |
cmdline=$(cat /proc/"$p"/cmdline | xargs -0) | |
if [ "$cmdline" == "$cmd" ]; then | |
kill $p | |
fi | |
done | |
fi | |
} | |
start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment