Re: Redirecting an nohup to a file when it is an error

joe_at_invalid.address
Date: 05/14/04


Date: Fri, 14 May 2004 15:00:46 GMT

rgaffuri@cox.net (Ryan Gaffuri) writes:

> My background jobs should result in an error. I want both the error
> and the standard out redirected to a given file. It says it is being
> redirected to nohup.out. This is in the korn shelll. Anyone know
> why?
...
> nohup run_script $ERROR_MSG_OPTION -u $LOGIN_FILE_NAME param1 2>&1 >
> myfile.log;

The order of redirection is important here. The above command
redirects stderr to stdout, then redirects stdout to a file, which
leaves stderr pointing at where stdout was. You need to do it this
way:

nohup run_script $ERROR_MSG_OPTION -u $LOGIN_FILE_NAME param1 > myfile.log 2>&1

This points stdout to the file, then points stderr to where stdout
currently goes (the file).

Joe

-- 
"Surprise me"
  - Yogi Berra when asked where he wanted to be buried.


Relevant Pages

  • Re: bash: how to restore output to the term after exec>FILE?
    ... redirects stdout to mail and leave stderr unaffected. ... Most Unixes offer more file descriptors 3,4,5,... ...
    (comp.unix.shell)
  • Re: Redirecting an nohup to a file when it is an error
    ... > redirects stderr to stdout, then redirects stdout to a file, which ... > leaves stderr pointing at where stdout was. ... myfile.log 2>&1; echo $? ...
    (comp.unix.programmer)
  • stderr handling (was: TCL and Python)
    ... Melissa Schrumpf wrote: ... >Also, I dislike the use of redirects in general, because I've had issues, ... >nmap using stdout instead of stdin, but I just couldn't get it to happen ... when I modified nmap to run ...
    (comp.lang.tcl)
  • stderr handling (was: TCL and Python)
    ... Melissa Schrumpf wrote: ... >Also, I dislike the use of redirects in general, because I've had issues, ... >nmap using stdout instead of stdin, but I just couldn't get it to happen ... when I modified nmap to run ...
    (comp.unix.programmer)
  • Re: Bash redirection question
    ... > directs both standard output and standard error to the ... > that the 1st example should have stdout redirected to ... > stdout, and not stderr. ... the example redirects stderr to go to where stdout is ...
    (comp.unix.shell)