Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 have a ruby script that writes to STDOUT and sometimes STDERR. I am running this script every 5 minutes via a crontab:

*/5 * * * * /root/myscript.rb >> /var/log/myscript.log 2>&1

What I've noticed is that the log file will not be written to in real time. Instead, it waits until the script has exited, and then all at once writes to that log file. I feel like I have other scripts that do not have this behavior, but perhaps I am mistaken.

Is this just how it works? Is there something I should look for to change this behavior?

This is Ubuntu 12.04

share|improve this question

Have your script log to syslog instead of stdout. Doing so is a much more flexible solution in the long term than logging to stdout.

share|improve this answer
Why do you say that? Sometimes I will execute this script manually, and it's nice to just have it write output directly to my console, instead of opening the syslog as well. – Brian Jul 25 '13 at 14:16
Syslog is the de facto logging standard on Linux. As such, tools for collecting, analyzing, and archiving syslog are numerous and of high quality. If you need console output, just modify your script to give verbose output if its run with a -v flag. – EEAA Jul 25 '13 at 14:21

Ah, I've found that Ruby will not automatically flush STDOUT/STDERR output after each write call. I placed STDOUT.sync = true at the top of my file and now it writes to STDOUT, and thus the log file, in real time.

share|improve this answer

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.