[clug] shell stdout and stderr

Kim Holburn kim.holburn at anu.edu.au
Thu Dec 1 04:00:24 GMT 2005


exec

rtfm: man bash (search for "exec " without the quotes):

       exec [-cl] [-a name] [command [arguments]]
               If  command is specified, it replaces the shell.  No  
new process

.....

               not  be executed.  If command is not specified, any  
redirections
               take effect in the current shell, and the return   
status  is  0.
               If there is a redirection error, the return status is 1.


On 2005 Dec 01, at 2:52 PM, Tony and Robyn Lewis wrote:

> In a bourne shell, I want to make all stderr (and stdout) go to  
> files, *from within that script* - i.e. the standard redirection  
> won't cut it.
>
> For example, if something like "File does not exist" is written to  
> stdout in my script, because it tries to run some non-existent  
> command, I want that to go to a file that I nominate, *from within  
> the script*
>
> pseudoscript:
>
> #!/bin/sh
>
> redirect_my_std_err /tmp/mystderr
> /run/this/missing/command
> exit 0
>
> I want the error of "sh: /run/this/missing/command: No such file or  
> directory" to end up in /tmp/mystderr
>
> Any clues?
>
> If you're curious why, it's because I've got a gazillion scripts  
> that I'm tidying up, and I want to generalise the stdout and stderr  
> of these things to go to a file that I can then mail to someone and/ 
> or append to some larger log file - a logging wrapper script.
>
> It's all working well for capturing stdout and stderr of the target  
> script (simple redirection), but not if something generates an  
> error within the log wrapper, such as being unable to find /  
> execute the target script/
>
> Clear?  Good.
>
> Pointers appreciated.
>
> Tony
>
> -- 
> linux mailing list
> linux at lists.samba.org
> https://lists.samba.org/mailman/listinfo/linux

-- 
Kim Holburn
Security Manager, National ICT Australia Ltd.
Ph: +61 2 61258620 M: +61 417820641  F: +61 2 6230 6121 aim://kimholburn
Email: kim.holburn at nicta.com.au  - PGP Public Key on request   
callto://kholburn
Cacert Root Cert: http://www.cacert.org/cacert.crt
Aust. Spam Act: To stop receiving mail from me: reply and let me know.

Use ISO 8601 dates [YYYY-MM-DD] http://www.saqqara.demon.co.uk/ 
datefmt.htm
Democracy imposed from without is the severest form of tyranny.
                           -- Lloyd Biggle, Jr. Analog, Apr 1961




More information about the linux mailing list