I'm using the trap command to capture any signals received whilst my script is running.
How's the best way of writing the signal and any other error messages to a file/error log' without having to type '2>$1' on the command line after the script name?
Cheers
s93366
July 14, 2004, 3:41pm
2
Hi
depends..
I use the logger command (it logs to syslog). It depends on what kind of error checking your script has..
output everything to a file is the simplest way..
/peter
Ygor
July 15, 2004, 9:25am
4
You could use the special command: "exec" to redirect stdout and stderr, e.g. if you put this at the top of your script ....
exec > /tmp/logfile$$ 2>&1
... all messages will go to the log file.
From man ksh...
exec [arg ...]
Parameter assignments remain in effect after the command completes. If arg is given, the command specified by the arguments is executed in place of this shell without creating a new process. Input/output arguments can appear and affect the current process. If no arguments are given, the effect of this command is to modify file descriptors as prescribed by the input/output redirection list. In this case, any file descriptor numbers greater than 2 opened with this mechanism are closed when invoking another program.