First of all, use a log coloring tool like colortail
, colorize
or ccze
.
In the more general case, the problem is that libc will automatically optimize throughput by buffering when stdout is not a terminal. This can dramatically reduces the number of syscalls for non-interactive jobs. For this and more, compare interactive and non-interactive output.
When the process thinks it's not interactive, while you know it is, there are several ways of convincing it to flush its buffers after each logical write:
The Wumpus's approach, interpretter instructions for changing buffering:
$|=1
or the equivalent STDOUT->autoflush(1)
in Perl
fflush()
after writing in awk
sys.stdout.flush()
after writing in Python
Program specific settings:
-u
in Python and GNU sed
--line-buffered
in GNU awk
Opening a PTY for the terminal, making stdout a TTY and circumventing the problem:
script -q /dev/null yourcommand
unbuffer
from the expect package
And finally $LD_PRELOAD
hacks that inject options into a process's C runtime (neatly wrapped in the GNU coreutils stdbuf
, suggested by Vilhelm)