I run a TACACS+ server which sends debug information to stderr. As I would like to grep specific data from this debug information, I redirected stderr to stdout: tac_plus -f /usr/local/etc/tac_plus.cfg 2>&1. However, looks like it actually did not go to stdout, because if I execute tac_plus -f /usr/local/etc/tac_plus.cfg 2>&1 | cat, then I see no output at all. On the other hand, ( echo blah >&2 ) 2>&1 | tr 'a-z' 'A-Z' works as expected:

$ ( echo blah >&2 ) 2>&1 | tr 'a-z' 'A-Z'

Could somebody explain this behavior? Shell is bash version 4.2.37.

  • 2
    are you sure tac_plus sends output to stderr? May be there is no output sent to stderr? – Hameedullah Khan May 31 '16 at 15:11
  • 4
    the output may be buffered to a pipe. Try prefixing the tac_plus command with stdbuf -oL -eL. – meuh May 31 '16 at 15:37
  • @HameedullahKhan Yes, because if I do tac_plus -f /usr/local/etc/tac_plus.cfg 2>/dev/null, then there is no output. On the other hand, in case I do tac_plus -f /usr/local/etc/tac_plus.cfg 2>logfile, then logfile has no content.. @meuh I tried with both stdbuf -oL -eL tac_plus -f /usr/local/etc/tac_plus.cfg 2>&1 | cat, but it did not change anything. – Martin Jun 1 '16 at 7:34

If we look at the sources we can see function report() which is used to print messages can be configured to write to stderr, or to use syslog(3) to get them logged. It also depends on what level of logging you configure. You can see if the command is doing any writes or syslog calls with eg:

strace -e write,connect -o /tmp/out tac_plus ...

Look the tmp file for lines like write(1,... or other numbers, probably 1 for stdout, 2 for stderr, and 3 or more for syslog as it is implemented by opening a socket with connect() and writing to it.

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.