Activate Screen Session Automatically


/ Published in: Bash
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.