Last active
November 11, 2020 13:04
-
-
Save japaz/99e6c99fcc0a7b60ff1a42333f6ba510 to your computer and use it in GitHub Desktop.
Improved rscreen from autossh
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/sh | |
# | |
# sample script to use autossh to open up a remote screen | |
# session, or reconnect to an existing one. | |
# | |
# $Id: rscreen,v 1.4 2002/05/07 17:54:13 harding Exp $ | |
# | |
if [ "X$1" = "X" ]; then | |
echo "usage: `basename $0` <host>" | |
exit 1 | |
fi | |
if [ "X$SSH_AUTH_SOCK" = "X" ]; then | |
eval `ssh-agent -s` | |
ssh-add $HOME/.ssh/id_rsa | |
fi | |
#AUTOSSH_POLL=600 | |
#AUTOSSH_PORT=20000 | |
#AUTOSSH_GATETIME=30 | |
#AUTOSSH_LOGFILE=$HOST.log | |
#AUTOSSH_DEBUG=yes | |
#AUTOSSH_PATH=/usr/local/bin/ssh | |
lp=null | |
# find a free listening port | |
for port in $(seq 20000 20020); do | |
lsof -i -n -P |grep LISTEN |grep -q ":${port}" | |
[ $? -eq 1 ] && { lp=$port; break; } | |
done | |
[ "$lp" = "null" ] && { echo "no free local ports available"; return 2; } | |
export AUTOSSH_POLL AUTOSSH_LOGFILE AUTOSSH_DEBUG AUTOSSH_PATH AUTOSSH_GATETIME AUTOSSH_PORT | |
autossh -M $port -t $1 "screen -D -R $2" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment