Skip to content

Instantly share code, notes, and snippets.

@bankair
Created April 29, 2014 12:08
Show Gist options
  • Select an option

  • Save bankair/11398290 to your computer and use it in GitHub Desktop.

Select an option

Save bankair/11398290 to your computer and use it in GitHub Desktop.
function get_free_port_starting_from() {
local PORT=$1
local QUIT=0
while [ "$QUIT" -ne 1 ]; do
lsof -i :$PORT> /dev/null
if [ $? -ne 0 ]
then
QUIT=1
else
PORT=`expr $PORT + 1`
fi
done
echo $PORT
}
function assh() {
local PORT=`get_free_port_starting_from 2000`
autossh -M $PORT -t $@
}
@bankair

bankair commented Apr 29, 2014

Copy link
Copy Markdown
Author

A bash function that find itself a free port to launch autossh

Usage:
assh [ssh parameters] [ssh host]

  1. Install autossh
  2. Source assh.bash
  3. Start your ssh session with assh
  4. Close the laptop.
  5. Go take a walk and enjoy the [sun/moon/girls/boys/whatever]
  6. Reopen the laptop.
  7. OMFGWTFBBQ !!! My session is still open, this shit is crazy !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment