0

Of course I know the function strace have a option -o,which can export the trace result into a local file.But I want to use the redirect command(>) here.

strace -e trace=file lastb|grep " = 0" >file

There is a logical problem here.The > follow the lastb.That is not my intention.Even I use a bracket cannot improve it like following:

(strace -e trace=file lastb)|grep " = 0" >file

So how to use the redirect command(>) to get a file contain the trace information?

yode
  • 1,047
  • 1
    Does strace not have a -o filename option for capturing trace output to filename? – steeldriver Jul 09 '17 at 13:21
  • @steeldriver Yes,I know,anyway thanks.But I want to use redirect command here.Is possible? – yode Jul 09 '17 at 13:23
  • Let's get this clear. You are piping the output of strace through grep, and redirecting the output of grep to a file. But that's not what you want? Are you using grep to select the trace information you want? Because if so, the first example would work OK. Or, are you trying to do that, but take a copy of the strace output into a file as well? – Bob Eager Jul 09 '17 at 13:45
  • @BobEager I want to redirect the output of grep to a local file. :) – yode Jul 09 '17 at 15:07

1 Answers1

2

strace prints to stderr, not stdout. You will need to redirect stderr to stdout if you want to pipe it.

strace -e trace=file lastb 2>&1|grep " = 0" > file

You can additionally suppress lastb's normal output by redirecting it to /dev/null (shorthanded here as &-)

strace -e trace=file lastb 2>&1 >&- | grep " = 0" file

If you are just wanting to see where lastb is getting its information, that is typically in /var/log/btmp

Laikulo
  • 164