error redirection


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers error redirection
# 1  
Old 05-12-2008
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  
Old 05-12-2008
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  
Old 05-13-2008
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  
Old 05-13-2008
To redirect subsequent errors of the current script, use exec:

Code:
exec 2>/path/to/stderr.log

# 5  
Old 05-14-2008
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  
Old 05-14-2008
There is no set -x there, try again.
# 7  
Old 05-15-2008
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
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unable to catch the redirection error when the disk is full

Hi Experts, Problem summary : I am facing the below problem on huge files when the disk is getting full on the half way through the execution. If the disk was already full , the commands fail & everything is fine. Sample Code : head_rec_data_file=`head -1 sample_file.txt` cat... (9 Replies)
Discussion started by: Pruthviraj_shiv
9 Replies

2. Shell Programming and Scripting

Error redirection question

Hi gurus, I have a question, need some of your inputs... I have a command like this : export LINE_COUNT=`wc -l test.dat | awk '{print $1}'` echo $LINE_COUNT --- > gives me 2 which is fine as the file has 2 lines. This works fine if the file test.dat is present but in case... (3 Replies)
Discussion started by: calredd
3 Replies

3. UNIX for Dummies Questions & Answers

about different redirection

explain the redirections 1>, 2>, 3>, ..... and 1< ,2<,3<..... where we use these things thanks Thread moved from AIX forum (2 Replies)
Discussion started by: tsurendra
2 Replies

4. Shell Programming and Scripting

redirection error

Hi i am facing a very strange problem suppose the parameters which i passed to the script is -o 140 then my code is as follows echo $* | awk '{ for ( i=0;i<=NF;i++){if ($i= -o) { print ${i+1} } } ' | read abc echo $abc abc=`echo $* | awk '{ for ( i=0;i<=NF;i++){if ($i= -o) { print... (5 Replies)
Discussion started by: aishsimplesweet
5 Replies

5. Shell Programming and Scripting

I/O Redirection: how can I redirect error msgs to a temp file

Hi there, I just want to know how can I redirect error msgs returned from running a command (e.g. nslookup) and then only print out the correct output using an if statement?. I've tried the following: where $a is a list of IPs. but I got all the error msgs printed out to screen and... (9 Replies)
Discussion started by: Abdulelah
9 Replies

6. Shell Programming and Scripting

Error with redirection in awk

I'm trying to find average of values in 2nd column in some files. Filenames have following pattern eg: tau_2.54_even_v1.xls tau_2.54_odd_v1.xls tau_1.60_v1.xls tau_800_v1.xls #!/bin/bash for file in pmb_mpi tau xhpl mpi_tile_io fftw ; do for f in "2.54" "1.60" "800" ;do if... (2 Replies)
Discussion started by: vishwamitra
2 Replies

7. Shell Programming and Scripting

output and error redirection

hi :) if condition >&- 2>&- Can anybody explain the redirection in above command Thanks in advance (1 Reply)
Discussion started by: jpriyank
1 Replies

8. Shell Programming and Scripting

sed error : Syntax error: redirection unexpected

My script is throwing the error 'Syntax error: redirection unexpected' My line of code.. cat nsstatustest.html | sed s/<tr><td align="left">/<tr><td align="left" bgcolor="#000000"><font color="white">/ > ztmp.Ps23zp2s.2-Fpps3-wmmm0dss3 HTML tags are getting in the way but they're needed to... (3 Replies)
Discussion started by: phpfreak
3 Replies

9. Shell Programming and Scripting

Error file Redirection

Hello All, I was wondering is there any other way in Shell Scripting to redirect the errors to a output file inside a shell script with using a error status checking or a command line redirection. Say without doing this ksh test.ksh 2> error.txt or without doing this ... if ; then... (3 Replies)
Discussion started by: maxmave
3 Replies

10. Shell Programming and Scripting

Redirection or piping error message

I have written a script that appears to work correctly in testing, but is coming up with a starnge error message, script_name: test: 0403-004 Specify a parameter with this command. Redirection or piping of stdin or stdout is allowed only with -b. (156). The script is run by different... (2 Replies)
Discussion started by: mariner
2 Replies
Login or Register to Ask a Question