I'm have program that executes in background another programs. 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 follows.-
Usually the log is merged for coherency, so stderr and stdout are logged contemporaneously in the same log, give or take some stdout buffering. Use redirection ">log_file 2>&1". You are making stderr become stdout and go to the outer log, and stdout goes to the three inner logs. Try that order on all your lines.
Plz one question, why changing the order of redirection would make a difference? what is the meaning of "2>&1" ? I think that 2>&1 is telling that standard error becomes standard output and logges to the same outer log, meaning log to "logFileA.txt" instead of the 3 inner log files.
I changed the redirection in the four command lines and it is still logging the Error Message to the Outer Log (logFileA.txt). How could I make it to log the Error to the 3 inner log files?
This discussion assumes that you are using a shell that uses basic Bourne shell redirection syntax (such as bash, ksh, or sh). The csh shell and its derivatives handle redirection differently.
The shell redirection operator 2>&1 tells the shell to redirect all ouput written to file descriptor 2 (the standard error output stream) to the file to which file descriptor 1 (the standard output stream) is directed. The order of the redirections is important. Try the following examples to see the difference.
EXAMPLE 1:
(echo abc;cp "unknown file" xyz)
This command will send the standard output from echo to your terminal and the standard error output to your terminal (unless you have performed redirections for one of these output streams that were not associated with another command).
If this isn't what happens, log out and log back in and try again to get a fresh shell execution environment with standard output and standard error output directed to your terminal.
EXAMPLE 2:
(echo abc;cp "unknown file" xyz) >fd1 2>fd2
This command will send the output from echo to the file named fd1 and the diagnostic message from cp to the file named fd2. You can verify this by running the commands:
cat fd1
and
cat fd2
EXAMPLE 3:
(echo abc;cp "unknown file" xyz) >fd1 2>&1
This command will send the output from echo to the file named fd1 and the diagnostic message from cp to the file to which file descriptor 1 is directed (which in this case is the file named fd1). Again, you can verify this by running the command:
cat fd1
EXAMPLE 4:
(echo abc;cp "unknown file" xyz) 2>&1 >fd1
This will send the diagnostic output from the cp command to the file to which file descriptor 1 is directed (your terminal) and the output from echo to the file named fd1.
send any output to logfileA.txt something is seriously wrong. This all works as I have described when tested on Mac OS X Version 10.7.5 with both bash and ksh. When I tried these using csh on OS X, it gives the diagnostic:
Ambiguous output redirect.
Of course there is one other possibility: Do program1a, program1b, and program1c internally redirect their output to logfileA.txt? If so, we have wasted a lot of time, and I assume you know how to fix your problem.