Monday, November 11, 2013

Autospawn screen session on ssh connection

This is particularly useful in a situation where your ssh connection always get disconnected, and you have no privilege to tweak the ssh server settings to avoid that.

  1. First method, simple and easy, but will create multiple screens if you have more ssh sessions: 
    echo "screen -R" >> ~/.bash_profile; source ~/.bash_profile
  2. 2nd method, smarter than the above, will attach to the existing screen session if there is any, and create new one if none is available 
    echo "if $(screen -ls | grep -q pts); then screen -x; else screen -R; fi" >> ~/.bash_profile; source ~/.bash_profile

No comments: