tags:

views:

28

answers:

1

I use logger command to log messages to /var/log/messages But How do I use logger to save the standard out, error out messages? Something like this does not work.

grep `date +'%y%m%d'` /var/log/mysqld.log | sed 's/^/computer /' | logger 2> logger
+2  A: 

You're confusing redirection to a process (pipes, or |) with redirection to a file (>).

You need to redirect stderr to stdout by using 2>&1, and then pipe (|) to your logger process.

e.g.

grep ....  2>&1 | logger

This assumes you're using sh or a variant. The syntax is different for csh. It's worth having a look at this excerpt from Unix Power Tools for more info (especially as your previous question seems strongly related).

Brian Agnew
I have just ordered "Unix Power Tools" book. Thanks for that link.I have not tested your command. But it must be working.
shantanuo