Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm having a bit of trouble with GNU's screen. What I want to do is this (from cron):

If a screen session named cron exists, add a new window to the session and launch a process in it (but do not attach to the session). Otherwise, create a new session called cron and launch the process in it (again, do not attach). If possible, all of this should be done using just one "screen" command.

I've already tried a bit but haven't come to a solution that satisfies all of my needs:

screen -S cron -dRRm screen ping
screen -S cron -X screen ping

Is there something I have missed?

share|improve this question

I don't think that you can do this in one command, but this should do what you want:

screen -ls cron | grep -q '(\w*tached)' >&- || screen -dmS cron
screen -S cron -X screen ping
share|improve this answer

You must log in to answer this question.

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