Sponsored Content
Top Forums Shell Programming and Scripting How get program name that produced an IO error redirected to a LOG in a nohup command? Post 302766415 by enriquegm82 on Monday 4th of February 2013 04:43:45 PM
Old 02-04-2013
Wrench It worked!

Quote:
Originally Posted by Don Cragun
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:
Code:
(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:
Code:
(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:
Code:
cat fd1

and
Code:
cat fd2

EXAMPLE 3:
Code:
(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:
Code:
cat fd1

EXAMPLE 4:
Code:
(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.


If the commands:
Code:
nohup nice -10 program1a > logfile1a.txt 2>&1
nohup nice -10 program1b > logfile1b.txt 2>&1
nohup nice -10 program1c > logfile1c.txt 2>&1

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:
Code:
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.
Don Cragun, thanks very much for the explanation. It was very clear and useful. It worked!

Thanks very much to Don Cragun and DGPickett.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

tail -f a log file redirected into a new window?

Is this possible? I am attempting to display a new xterm window and tail -f the log file within that new window. I am currently working on a solaris 8 machine if that has any different meaning than the other platforms. As you can see, I am a newbie to this forum and to UNIX. Any help would be... (2 Replies)
Discussion started by: douknownam
2 Replies

2. UNIX for Dummies Questions & Answers

Nohup Command

Hello All, I am newbie to unix.I am trying to use NOHUP command in shell script it works fine with only "nohup test.sh 10 &" and "/opt/user/nohup test.sh 10 &" gives an error saying "ksh: /opt/user/nohup : not found". Can anybody please guide me to make it work. Thanks Blazix (9 Replies)
Discussion started by: blazix
9 Replies

3. UNIX for Dummies Questions & Answers

Ignoring files that are currently being produced

Hi! Letīs say I want copy dump-files to a location. These dump-files vary between 80 and 280MB and will be produced in about 1min or less. I have a cronjob which (not only) copies those. So how can I find out whether a file is currently produced or not? Because if my script works with these... (2 Replies)
Discussion started by: cypher82
2 Replies

4. UNIX for Dummies Questions & Answers

nohup command..

Hi.. Can anybody tell me, what exactly the nohup command does & when is it used? Your help is appreciated. (3 Replies)
Discussion started by: Amol21
3 Replies

5. Programming

Want to get /var/log/messages redirected to a FIFO ...

Is it possible that I get all the syslog messages from /var/log/messages redirected to some FIFO as and when any new messages comes. In exact, I need to duplicate the messages to a FIFO, the moment a new message is logged; from where another process reads and does some processing without... (12 Replies)
Discussion started by: Praveen_218
12 Replies

6. Solaris

Error messgaes can not be redirected

# whoami 2>/dev/null whoami: not found # Why the error message not getting redirected to /dev/null ... The shell is # echo $SHELL /sbin/sh For other commands it is working # ls aaa 2>/dev/null # Is there any other way to redirect the err msg from whoami Thank you for your... (7 Replies)
Discussion started by: Anu_1
7 Replies

7. AIX

Nohup command

I'm trying to run a compress script in the background, but I even though the script is running in the background I get "Sending nohup output to nohup.out." and the screen just stays there. How can I make the script run in background and make my command prompt come back. I was using: nohup... (2 Replies)
Discussion started by: NycUnxer
2 Replies

8. UNIX for Dummies Questions & Answers

Make - two target produced by one recipe

Suppose executable X produces files A and B from nothing, Y produces C from A, Z produces D from B, and my final goal is to produce C and D. I wrote the following makefile: .PHONY: all all: C D C: A Y A D: B Z B A B: X This makefile seems to reflect all dependencies, as it should... (2 Replies)
Discussion started by: ybelenky
2 Replies

9. UNIX and Linux Applications

missing delimiters when mysql output is redirected to log file

Hi, Pls check that '|' and '+' present in Step-1 are not copied to log file in Step-3. Pls suggest how to get the exact output from Step-1 (i.e. with out losing '|' and '+') in to a log file ~Thanks Step-1: Execute command > mysql -utest -ptest -htesthost testdb -e "select * from... (3 Replies)
Discussion started by: newbielgn
3 Replies

10. UNIX for Dummies Questions & Answers

Dot and redirected output syntax in a tar command

Hi All, Please could anyone advise what the purpose of the dot syntax in the following command means: tar -cvf ${WORKING_BACKUP_ROOT}/${TAR_ARCHIVE_FILE} . >/${BACKUP_ROOT}/${ARCHIVE_LOG} Many thanks (2 Replies)
Discussion started by: daveu7
2 Replies
All times are GMT -4. The time now is 05:07 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy