Skip to content

Instantly share code, notes, and snippets.

@zcoder
Forked from yurial/ssh-sc
Created November 21, 2011 10:36
Show Gist options
  • Save zcoder/1382270 to your computer and use it in GitHub Desktop.
Save zcoder/1382270 to your computer and use it in GitHub Desktop.
ssh - screen
#!/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
if [ -n "$PARAMS" ]
then
while [ 1 ]; 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;
fi;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment