Skip to content

Instantly share code, notes, and snippets.

@vivisidea
Created March 4, 2013 03:50
Show Gist options
  • Save vivisidea/5079782 to your computer and use it in GitHub Desktop.
Save vivisidea/5079782 to your computer and use it in GitHub Desktop.
a simple script to connect ssh.proxy server automatically.
#!/bin/bash
# file ssh.proxy
# created by make-template :)
# vivi@2012-02-20_21:30:05
#
# a simple script to connect ssh.proxy server at startup
# and handle the broken pipe error automatically
#
ROOT=$HOME/scripts/ssh.proxy
WAIT=5
PILL=$ROOT/pill
LOG=$ROOT/../ssh.log
SERVERS=(s{1,2}.alissh.com)
USER=jmepvcts
PORT=56
COUNT=${#SERVERS[@]}
function logger(){
local MSG=$1
local TIMESTAMP=$(date '+%F %H:%M:%S')
echo "$TIMESTAMP: $MSG" >> $LOG
}
function random_server(){
local INDEX=$(( $RANDOM % $COUNT ))
echo -n ${SERVERS[$INDEX]}
}
# 开机连无线需要一段时间
sleep 20
notify-send -t 5000 "starting ssh.proxy :)"
while [ 1 ] ; do
if [ -f $PILL ]; then
rm $PILL
echo "pill file detected, exiting main loop"
break
fi
SERVER=$(random_server);
logger ".............connecting to server: $SERVER:$PORT.............."
sshpass -f "$ROOT/ssh.proxy.pass" ssh -2 -gCNvD 7071 $USER@$SERVER -p $PORT \
-o PasswordAuthentication=yes \
-o ChallengeResponseAuthentication=no \
-o GSSAPIAuthentication=no \
-o HostbasedAuthentication=no \
-o PubkeyAuthentication=no \
-o RhostsRSAAuthentication=no \
-o UserKnownHostsFile=/dev/null \
-o StrictHostKeyChecking=no \
-o RSAAuthentication=no >> $LOG 2>&1
notify-send -t 1000 "ssh maybe broken, try restarting in $WAIT seconds"
sleep $WAIT
done
~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment