Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a program that executes other programs in the background. The main program would be programA, and the programs executed by the main one, would be program1a, program1b and program1c.

I need the programs to continue the execution no matter if the shell connection is lost, so I'm using the nohup command.

However, each program has its own log file, like this:

programA --> logfileA.txt
program1a --> logfile1a.txt
program1b --> logfile1b.txt
program1c --> logfile1c.txt

When an error occurs in one of the child programs, the error message is displayed in the LOG file corresponding to the main program.

Examples:

  1. The programA is invoked from another routine.-

    nohup nice -10 programA 2>&1 > logfileA.txt
    
  2. Inside programA it invokes the other 3 programs.-

    nohup nice -10 program1a 2>&1 > logfile1a.txt
    nohup nice -10 program1b 2>&1 > logfile1b.txt
    nohup nice -10 program1c 2>&1 > logfile1c.txt
    

When an error occurs, it is showm or displayed in logfileA.txt, instead of being displayed in logfile1a.txt or logfile1b.txt or logfile1c.txt.

How can I know what program produced the error that is displayed in the main program's log file?

share|improve this question
    
does anything get logged to the logfile1a.txt or 1b/1c for that matter ? I mean anything else, not only errors. I am sure program1a has some output that you keep in its logfile. Is it only when this error happens to take place, it skips the child logs and goes straight to the parent process log or for everything it is the parent process' log ? –  Mel_Burslan Feb 2 '13 at 0:07
add comment

1 Answer 1

You probably just need to swap the order in which you redirect:

nohup nice -10 program1a  > logfile1a.txt 2>&1
nohup nice -10 program1b  > logfile1b.txt 2>&1
nohup nice -10 program1c  > logfile1c.txt 2>&1

the meaning of 2>&1 is "duplicate fd 2 from fd 1", this happens before the redirection of fd 1 via ">" in the example you gave.

See also: Why is redirecting STDERR to /dev/null done this way?

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.