LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] Logging hack wanted

[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
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


Maintained by the ILUG website team. The aim of Linux.ie is to support and help commercial and private users of Linux in Ireland. You can display ILUG news in your own webpages, read backend information to find out how. Networking services kindly provided by HEAnet, server kindly donated by Dell. Linux is a trademark of Linus Torvalds, used with permission. No penguins were harmed in the production or maintenance of this highly praised website. Looking for the Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!
RSS Version
Powered by Dell