Stdout or a Pipe and a Tee

Posted on March 9, 2010 by nseidm1.
Categories: log, mail, pipe, stdout, tee.

If you have a binary that is outputting information to standard output, you can save the information 2 ways. You can direct the output to a file using >> or you can use a pipe with a tee. When you use >> you will not see the output, it will directly get dumped into the file, which is why the pipe and the tee is useful. Lets say you want to monitor your your mail.log. Open it with tail -f, and watch it on the screen:

sudo tail -f /var/log/mail.log

I find it interesting sometimes to watch spam and viruses get processed by the server.

Now if you want to save this output to a file other than the default mail.log you can direct the stdout to a file using >>:

sudo tail -f /var/log/mail.log >> ~/mail_bak.log

If you want to view the tail, while you are also saving it to a backup log file, use:

sudo tail -f /var/log/mail.log | tee ~/mail_bak.log

Two options, I use them both on occasion.

no comments yet.

Leave a comment

Names and email addresses are required (email addresses aren't displayed), url's are optional.

Comments may contain the following xhtml tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>