views:

60

answers:

3

Hi all,

I'm trying to setup a simple logging framework in my shell scripts. For this I'd like to define a "log" function callable as

log "LEVEL" $message

Where the message is a variable to which I have previously redirected the outputs of executed commands. My trouble is that I get errors with the following

{message=command 2>&3 1>&3 3>&-} >&3
log "INFO" $message

There's something wrong isn't there?

TIA

+1  A: 

Perhaps you want:

message=$( command 2>&1 )
log INFO "$message"
glenn jackman
I ended up doing that and switching log destination on command return value.Thanks
Eddy
Hi, that's what I ended up doing, together with an if switch to check the command return value and set the log category appropriately.thanks,Eddy
Eddy
A: 

In addition to the $(), you need to use spaces and a semicolon with your curly braces (if you even need them):

{ command; }
Dennis Williamson
A: 
Norman Ramsey
Hi that would be a good one but I don't have access to syslog configuration.Thanks anyhoweddy
Eddy