Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Using TRAP command

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 07-14-2004
dbrundrett dbrundrett is offline
Registered User
 
Join Date: Jan 2002
Last Activity: 9 May 2005, 8:52 AM EDT
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Using TRAP command

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
Sponsored Links
    #2  
Old Unix and Linux 07-14-2004
s93366's Unix or Linux Image
s93366 s93366 is offline
Registered User
 
Join Date: Apr 2002
Last Activity: 4 August 2011, 11:04 AM EDT
Location: Sweden / Stockholm
Posts: 168
Thanks: 0
Thanked 1 Time in 1 Post
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
Sponsored Links
    #3  
Old Unix and Linux 07-15-2004
dbrundrett dbrundrett is offline
Registered User
 
Join Date: Jan 2002
Last Activity: 9 May 2005, 8:52 AM EDT
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks for your reply
    #4  
Old Unix and Linux 07-15-2004
Ygor's Unix or Linux Image
Ygor Ygor is offline Forum Advisor  
Advisor
 
Join Date: Oct 2003
Last Activity: 15 May 2015, 11:55 AM EDT
Location: 54.23, -4.53
Posts: 1,801
Thanks: 1
Thanked 112 Times in 98 Posts
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...
Quote:
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.
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
trap command ahmad.diab Shell Programming and Scripting 3 08-18-2011 10:54 AM
trap command ramshree01 UNIX for Advanced & Expert Users 4 06-23-2011 11:30 PM
Use of TRAP Command Deepakh Shell Programming and Scripting 2 12-12-2006 03:24 AM
trap command mobile01 UNIX for Dummies Questions & Answers 1 11-30-2006 10:54 AM
trap command onlyc UNIX for Dummies Questions & Answers 3 07-11-2006 03:15 AM



All times are GMT -4. The time now is 01:26 PM.