Skip to content

Instantly share code, notes, and snippets.

@yurial
Created November 21, 2011 09:06
Show Gist options
  • Save yurial/1382101 to your computer and use it in GitHub Desktop.
Save yurial/1382101 to your computer and use it in GitHub Desktop.
ssh - screen
$ cat .bin/ssh-sc
#!/bin/bash
RET=1
PARAMS=
SESSION="auto-$RANDOM$RANDOM"
until [ -z "$1" ]; do
case "$1" in
'-S')
RET=1
shift
SESSION="$1"
;;
'-r' | '-x')
RET=255
shift
SESSION="$1"
;;
*)
PARAMS+=" $1"
;;
esac
shift
done
while [ 0 ]; do
case $RET in
'1') #new session needed
echo "Session '$SESSION'"
ssh $PARAMS -t screen -S $SESSION
RET=$?
;;
'255') #restart session
echo "Restart session '$SESSION'"
ssh $PARAMS -t screen -x $SESSION
RET=$?
if [ $RET = 255 ]; then
sleep 1;
fi
;;
'0')
echo "Session '$SESSION' done"
exit 0
;;
*)
echo "Session '$SESSION' error"
exit $RET
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment