[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: doc/TODO up-to-date

On Mon, Nov 03, 2003 at 11:24:23AM -0500, Joey Hess wrote:
>   * There needs to be a centralised logging method. Syslog will do, but
>     we currently have a lot of nasty code that appends messages to
>     /var/log/messages directly. All of that would be converted to pipe it
>     to logger. However, this is a problem, because piping a command to
>     logger loses the exit status of the command. Need some way to run a
>     command, logging the ouput to syslog, w/o losing exit status.

I suggested a solution for this a while ago:

  ((echo hello world; false; echo $? >&3) | logger) 3>&1

You then get the exit status on stdout. Generalizing a bit:

  to_syslog () {
    return "$((("$@"; echo $? >&3) | logger) 3>&1)"

This works for me in my tests using bash, anyway. Somebody might want to
check that the "$(..."..."...)" construction works in dash.


Colin Watson                                  [cjwatson@flatline.org.uk]

Reply to: