Posted By

wesalvaro on 08/05/10


Tagged

screen


Versions (?)

Activate Screen Session Automatically


 / Published in: Bash
 

  1. if [[ "$STY" == "" ]]; then
  2. screen -r > .screenResult
  3. if [[ $? == 1 ]]; then
  4. export whoami=`whoami`
  5. export total=`cat .screenResult | grep -i "attached" | wc -l`
  6. export s=$[`cat .screenResult | grep "${whoami}-AS" | grep -iv "attached" | wc -l`]
  7. if [[ $s == 0 ]] ; then
  8. echo 'Starting new screen session as no unattached screen exist'
  9. screen -S ${whoami}-AS
  10. else
  11. export screenSessionCount=$[$s-1]
  12. echo 'Resuming the first of ' $screenSessionCount 'screen sessions'
  13. export r=`screen -r | tail -n $s | head -n 1 | awk -F. '{printf "%d\n", $1}'`
  14. screen -r $r
  15. fi
  16. else
  17. echo 'Resumed single screen'
  18. fi
  19. else
  20. echo "You are on screen $WINDOW! "
  21. fi

Report this snippet  

You need to login to post a comment.