how to attach to a screen if there is one already or start a new one if it doesnt exist without detaching from other devices [closed]

StackOverflow https://stackoverflow.com/questions/22821288

  •  26-06-2023
  •  | 
  •  

Question

I am trying to configure screen on my RPi and I want to use Screen as my default shell so that I can get the same data of what I was doing on PI whenever I login from any of the device connected in same network. I understand that I can start screen by default in by .profile file. I want to know which argument I should use so that if i login from another device, then it shouldnt start a new one but connected to an existing one. If there is no existing one, then it should a new one. However I dont want it to get detached from other devices. This way i can ensure that there is only one screen and everybody access the same screen and can see who is doing what.

Was it helpful?

Solution

Write a if-else loop

pseudo code:-

if ((screen -ls)!=null){screen -r tosomescreen}
else{ //start new screen}

Hope this helps..!!

OTHER TIPS

The -R option attaches to the first detached session found, or else creates a new session.

screen -R -S newsession

This will attach to a detached session if found, ignoring the -S option. Otherwise, a new session named "new session" is created and attached.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top