The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Error file Redirection maxmave Shell Programming and Scripting 3 04-23-2008 01:17 PM
redirection DNAx86 Shell Programming and Scripting 9 04-18-2008 03:24 PM
sed redirection myle UNIX for Dummies Questions & Answers 3 03-12-2008 07:04 PM
Redirection or piping error message mariner Shell Programming and Scripting 2 05-10-2005 04:04 PM
Help with redirection Shallon1 High Level Programming 2 12-12-2001 07:35 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-12-2008
sais sais is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 36
error redirection

i am using 2> to redirect all the standard errors that i get in my bash script.. this command needs to be given in all the statements for which the errors are to redirected..
is there a command that will catch all the errors in all the shell commands that are present inside a script .? pls help..
  #2 (permalink)  
Old 05-12-2008
penchal_boddu penchal_boddu is offline
Registered User
  
 

Join Date: Apr 2008
Location: Bangalore
Posts: 127
Instead of having redirection for individual statements in a script,
i think u can have like this

script 2>path_of_file( or /dev/null)


Thanks
penchal
  #3 (permalink)  
Old 05-13-2008
sais sais is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 36
u mean it should be filename 2>path_of_error _file .... also can i give this command inside the script or should it be given in a command prompt
  #4 (permalink)  
Old 05-13-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
To redirect subsequent errors of the current script, use exec:

Code:
exec 2>/path/to/stderr.log
  #5 (permalink)  
Old 05-14-2008
sais sais is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 36
hi era
exec 2>/path/to/stderr.log ....
this command seems to be like an alternate for using -x when we run a script.... it directs not just the error but all the commands and the step wise execution for that program....
i would like to redirect only the standard errors of all the commands in a program .... any idea for that ..
  #6 (permalink)  
Old 05-14-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
There is no set -x there, try again.
  #7 (permalink)  
Old 05-15-2008
sais sais is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 36
hi era ,
what i mentioned there was we giving sh -x filename.sh gives us step wise execution of the program and if i give exec 2>path/file inside a script ...
and when i open the file that is getting created it contains a step wise execution of the program...
this is what i give in the script...
#!bin/sh
cd /NRS
#exec 2>error_$tar_name.log
sql_inp=/NRS/sql.inp
sql_log=/NRS/sql.log
if [ -f /NRS/inp.txt ]
then
echo "Data file /NRS/Bin/inp.txt exists"
else
echo "Data file /NRS/Bin/inp.txt does NOT exists"
exit
fi
# to remove comments from the file inp.txt
grep -v \# /NRS/inp.txt > /NRS/temp_inp

nol=`wc -l temp_inp | awk '{print$1}'`
if [ $nol -ne 2 ]
then
echo "supply all the necessary arguements in the inp.txt file "
else
tar_name=`head -1 temp_inp | tail -1`
ip_addr=`head -2 temp_inp | tail -1`
#usr=`head -3 temp_inp | tail -1`
#pwd=`head -4 temp_inp | tail -1`
fi
log=/NRS/$tar_name.log

etc....

and when i open the error_$tar_name.log :

+ [ -f /NRS/inp.txt ]
+ echo Data file /NRS/Bin/inp.txt exists
+ grep -v # /NRS/inp.txt
+ awk {print$1}
+ wc -l temp_inp
nol=2
+ [ 2 -ne 2 ]
+ tail -1
+ head -1 temp_inp
tar_name=star_nrs_4_25_0.tar.Z
+ head -2 temp_inp

what i had asked was whether can i redirect only the stderrors that i might get .... becoz this is a very big program and has some where around 600 commands that i need to perform so instead of giving 2> at the end of each command can i redirect all of them at one go ...
thanks
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 02:58 PM.


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

Content Relevant URLs by vBSEO 3.2.0