-
-
Save zcoder/1382270 to your computer and use it in GitHub Desktop.
ssh - screen
This file contains 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/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