0
screen -list
There are screens on:
        4278.chat       (07/16/15 14:26:47)     (Detached)
        15127.notifier  (07/16/15 13:27:57)     (Detached)

My goal is to :

  • If chat screen is not started then start it, otherwise close it.
  • execute a command in chat session (ex: node chat.js)
  • detach chat session

1 Answer 1

1

Multi-part answer:

  • If chat screen is not started then start it, otherwise close it.
screen -S chat -X quit || screen -S chat

Could also detach rather than kill the screen session, if that's what you meant.

  • execute a command in chat session (ex: node chat.js)

If you mean to start a new screen and execute a command, then

screen -dm -S chat && screen -S chat -X stuff 'command-to-execute-in-screen-subshell
'

Note the embedded new-line inside the quotes. If the screen is already running, you can leave off the first half.

  • detach chat session
screen -S chat -X detach

see also answer to first question.

All of this is reasonably documented in the manual.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .