Unix Programming - Redirecting an nohup to a file when it is an error

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > May 2004 > Redirecting an nohup to a file when it is an error





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Redirecting an nohup to a file when it is an error
Ryan Gaffuri

2004-05-14, 12:49 pm

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?


echo LOGIN_FILE_NAME $LOGIN_FILE_NAME

nohup run_script $ERROR_MSG_OPTION -u $LOGIN_FILE_NAME param1 2>&1 >
myfile.log;
message "$? FILE1" $STATUS_FILE &
nohup run_script $ERROR_MSG_OPTION -u $LOGIN_FILE_NAME param1 2>&1 >
myfile2.log;
message "$? FILE2" $STATUS_FILE &
wait
if [ $STATUS -eq 0 ]; then
echo checking grep
echo STATUS_FILE $STATUS_FILE
ERROR_VAR=`grep "^1" $STATUS_FILE | cut -f2 -d" "`
echo ERROR_VAR $ERROR_VAR
if [ ! "$ERROR_VAR" = "" ]; then
message "ERROR A failure occured!" $ERROR_MSG
tmp_file_cat $ERROR_MSG $ERROR_VAR
STATUS=1
fi
fi


message is just an echo to a file.

Here is the output


Sending output to nohup.out
Sending output to nohup.out
joe@invalid.address

2004-05-14, 12:49 pm

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.
Ryan Gaffuri

2004-05-22, 10:27 pm

joe@invalid.address wrote in message news:<m3n04bkq8y.fsf@invalid.address>...
> rgaffuri@cox.net (Ryan Gaffuri) writes:
>
> ...
>
> 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



how do i get this to run in teh background

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

but echo the $? back to the calling script? This is not running in the
background at all.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com