Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Due to Gnu Screen being hard to Google for, I've been having trouble finding an answer to this one.

As a concrete (what are you trying to do) example:
Running a server process (under linux) starts up a bunch of output (STDOUT STDERR) which can take input from STDIN.
Periodically I want to issue a command (/snapshot) to backup the current state.
I want to setup cron to run a command that occasionally injects this into the STDIN for the server.

So far I've been thinking that the server process could run in a detached screen session. And I think that screen's exec command can connect to different terminal sessions under screen and hand STDIN and STDOUT to another process. But reading the docs has been confusing. And it doesn't help that they say there's a "confusing illustration" to explain this further.

If anyone has done this, how do I specify a cron command to accomplish this. So far I'm thinking (show what you've done):

5 * * * * /usr/bin/screen -p 1 -X 'exec ! echo "/snapshot"'

But here I don't know if that'll work, if that would actually target the server process in window 1, and what happens after that; does screen exit?

share|improve this question
./~ Someday my answerer will come ./~ – dlamblin Dec 17 '11 at 22:32

1 Answer 1

up vote 1 down vote accepted

I don't think I fully understand your concrete use case, but here's a possible approach which may help.

Rather than have your process dump to stdout and stderr, have those written to a file. Alternately, you could use tee to write to a file and to the terminal.

Also redirect stdin using tail -f on a separate input file. Create a cron job which writes a new line to the input file at the appropriate interval.

You can still run your process in screen if you want to periodically check on it (or just to keep it alive).

Start your process like:

tail -f /path/to/myinputfile.txt | myprocess 2&>1 >/path/to/outputfile.txt

or, using tee:

tail -f /path/to/myinputfile.txt | myprocess 2&>1 | tee /path/to/outputfile.txt

And set up the input cron job like:

5 * * * * /bin/cat "/snapshot" >> /path/to/myinputfile.txt
share|improve this answer
Thanks; I like this solution. I thought screen might support something like this too though; E.G. if I only wanted to send a character or two without a newline the tail -f would be an issue. – dlamblin May 21 '12 at 19:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.