2

I am using Screen like this:

screen -L -dm -S session1 -c "./game_server -options"

to wrap around game servers. I log their output to a file and can send them input with:

screen -r session1 -p0 -X "stuff \"this into input^M\""

The timeout between log file flushes can be specified in the configuration file (10 seconds in my case).

The problem I have is that I can't force screen to flush output to the logfile. For example, after I send a "status" command to a game server, the game server prints some information, but it takes at least 10 seconds to add that to the log file.

I have tried sending:

screen -r session1 -p0 -X "logfile flush 1"

But it doesn't react to that. I've also tried flush 0 with no luck.

I wouldn't want to always log with a timeout of 1 second; it's only really needed after receiving a command. Note that I'm paranoid about performance here because the session is running a game server after all.

How can I force screen to flush output to the logfile? Is there a way to do what I need (log output to file and send commands to input) other than with screen, maybe with a FIFO?

2 Answers 2

4

Try this:

screen -r session1 -X colon "logfile flush 1^M"

logfile flush 1 isn't actually a screen command, but colon is. The next thing you pass is the argument to it which has to be quoted and the ^M at the end should actually be a Ctrl-M. Ctrl-V followed by Ctrl-M will generally do the trick for entering an actual Ctrl-M.

1
  • Thank you very much. Also, I was having problems with Ctrl-V Ctrl-M: it did print ^M in the command line, but then simply printed ^M in the screen window. Might have been the quotes. I ended up using this: screen ... -X stuff "$(printf '%b' 'this into input\015')".
    – Gipsy King
    Oct 19, 2010 at 12:49
1

I had the exact same need as you. Logfile flush is a valid command to send to screen - however, it doesn't need to be quoted, and you can also set it to 0 for instant flushing.

Change your line to

screen -r session1 -p0 -X logfile flush 0

Make sure to change it back when you are done reading from the log file though

screen -r session1 -p0 -X logfile flush 10

The default is 10 seconds, but you can set it to whatever you think is appropriate.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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