0

When I run dstat from a kernel 2.6 CentOS 6 64 bit. I got the following output:

# sed -n '4p' <(dstat -dl --float --nocolor 1 1) | awk -F '|' '{print $1,$2}' | awk '{print $1,$2,$3}'
Module dstat_disk24old failed to load. (No suitable block devices found to monitor)
0 0.01 0

What's interesting is this line:

Module dstat_disk24old failed to load. (No suitable block devices found to monitor)

When I append | grep -v failed or 2> /dev/null, it doesn't filter out this line. When I append > a.txt, this line also doesn't go to a.txt. So I'm wondering which stream this line goes to, even if it is printed on the screen?

  • 2
    Presumably standard error, file descriptor 2. That normally goes to the screen. You can check by redirecting it with 2> filename. – Tom Zych Dec 18 '15 at 1:46
2

It went to standard error, which is default to file descriptor 2. While in cmd1 | cmd2, only standard out of cmd1 was redirected to standard in of cmd2.

As a convention, all error and diagnostic messages will go to standard error.

You can use strace to confirm:

$ strace -e write dstat -dl --float --nocolor 1 1
write(2, "Module dstat_disk24old failed to"..., 83Module dstat_disk24old failed to load. (No suitable block devices found to monitor)) = 83
write(2, "\n", 1
)                       = 1
write(1, "\33[7l---load-avg---\n 1m   5m  15m"..., 34---load-avg---
 1m   5m  15m 
) = 34
write(1, "   0    0    0\n", 15   0    0    0
)        = 15
write(1, "   0    0    0\n", 15   0    0    0
)        = 15
+++ exited with 0 +++

You must redirect standard error to standard out if you want pipe to capture standard error output:

dstat -dl --float --nocolor 1 1 2>&1
  • Thanks. I see. I tried to redirect the error to the black hole /dev/null, but I was too late. Looks like I should do it before the first |. – Elgs Qian Chen Dec 18 '15 at 2:02
1

This > file redirector works on standard out. Since you also said grep could not see it, have you considered it to be standard error? To confirm and capture if indeed it is stderr, try:

yourlongcommand 2> error.log

And examine error.log.

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.