The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
direct output to a file then email it llsmr777 UNIX for Dummies Questions & Answers 2 11-21-2007 02:21 AM
How to direct FTP command to use a specific IP add or NIC ? pray44u SUN Solaris 5 06-02-2006 12:49 AM
Direct disk access Lopatonosec High Level Programming 3 05-31-2005 12:39 PM
Error: No direct declarator preceding "(" nik High Level Programming 1 05-17-2004 08:54 AM
direct transmission of files via TCP/IP darkspace High Level Programming 5 08-26-2002 02:00 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-20-2006
rony_daniel rony_daniel is offline
Registered User
  
 

Join Date: Oct 2005
Posts: 18
Re-direct the error msg to log file

Hi All,

I have an expression as follows:-
a=`expr ${i} + ${j}` >> $log_file 2>&1

Here, if any of the values i or j or both happens to be empty then the "expr" returns error as
"expr: 0402-050 Syntax error." My problem is I am not able to re-direct this error to the log file. Its is getting displayed
on the console itself which I don't want to. Any help please.....
  #2 (permalink)  
Old 11-20-2006
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
OK, first thing first, you're also trying (in a syntactically incorrect way) to append STDOUT to the log too (which would never actually assign anything to the variable.... if the whole thing was enclosed in backticks... ).

I believe that you want this:

Code:
a=`expr ${i} + ${j} 2>>${log_file}`
Cheers
ZB
  #3 (permalink)  
Old 11-20-2006
rony_daniel rony_daniel is offline
Registered User
  
 

Join Date: Oct 2005
Posts: 18
Thanks zazzybob

It worked for me. I did the following:-
Code:
a=`expr ${i} + ${j} >> $log_file 2>&1`
Now the error is going to the log file and not to the console. But please tell me what is wrong with the way I am doing for >> $log_file 2>&1. I want to append both the output as well as any errors to the log file. Please correct me if I am wrong.
  #4 (permalink)  
Old 11-20-2006
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
But you also want to assign to a variable, correct?

Code:
a=`( expr $i + $j | tee -a $log_file ) 2>> $log_file`
Now, STDOUT goes to the $log_file, and is stored in the variable. STDERR is appended to the logfile.

Cheers
ZB
  #5 (permalink)  
Old 11-21-2006
rony_daniel rony_daniel is offline
Registered User
  
 

Join Date: Oct 2005
Posts: 18
You are right zazzybob. I got carried away!!

The variable "a" was not getting populated with the value returned by the expression, with my code.

Your code just works perfect. Once again Thanks.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 09:27 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0