[ILUG] Logging hack wanted
Kenn Humborg
kenn at bluetree.ie
Thu Jan 27 13:29:23 GMT 2000
> The only way I can figure to pipe stderr to another command is
>
> $ cmd > /dev/null 2> /dev/tty1 | another_cmd
... and that won't work when you're on a different terminal,
or when you don't even have a terminal.
>
> I'm sure there must be an easier way? But I couldn't anything like just
>
> $ cmd 2> | another_cmd
>
> to work.
OK then, _I'll_ read the docs for you. Pay attention:
$ cmd 2>&1 1>/dev/null | another-cmd
According to the bash man page, 2>&1 says "make fd 2
a duplicate of fd 1". Note that this is a 'deep copy',
i.e. subsequently modifying fd 1 will have no effect on
fd2. So fd 2 (stderr) now writes to the same place
as fd 1 (stdout).
1>/dev/null means "open /dev/null for write on fd 1".
So stdout now writes to the bitbucket.
The original poster wanted to date stamp and log the
stuff coming from 'cmd'. Try using the logger command:
$ cmd 2>&1 1>/dev/null | logger -p local1.info
and configure syslog to write local1.info to /var/log/whatever.
Later,
Kenn
More information about the ILUG
mailing list