Error handling for sort command


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Error handling for sort command
# 1  
Old 12-26-2012
Error handling for sort command

Hello,

I need help in logging the error to the error log of one of sort command which i'm using and terminate the process if sort command is not able to execute.

Code:
sort -k 1.10,1.20n -o $outputfile $inputfile

how can i achieve the above.
# 2  
Old 12-26-2012
Assuming you're using a POSIX conforming shell (such as ksh or bash):
Code:
if ! sort -k 1.10,1.20n -o $outputfile $inputfile 2>error_log
then    echo "terminating; sort failed"
        exit 1
fi

# 3  
Old 01-03-2013
Hey, sorry for the late reply..

i tried with the above approach but it was giving me error something like [555] could not found ! ...
Anyways i went with the below approach and the process was terminating if sort is not working

Code:
sort -k 1.10,1.20n -o $inputfile $outputfile 2>>  error_log
pgmcc=$?
 
if [[ $pgmcc != 0 ]]
then
echo "FATAL ERROR, TERMINATING NOW"
fi

In this case i'm just getting the error written in error_log as sort: A write error occured while sorting.

But i want to capture error which comes on the console something like below:

Code:
vxfs: msgcnt 5980 mesg 001: V-2-1: vx_nospace - /dev/vx/dsk/drd_rootdg/tmpvol file system full (2 block extent)

Is there a way if i can achieve the above...??

Last edited by Scrutinizer; 01-03-2013 at 01:23 PM.. Reason: code tags
# 4  
Old 01-03-2013
Quote:
Originally Posted by mehulleo
Hey, sorry for the late reply..

i tried with the above approach but it was giving me error something like [555] could not found ! ...
Anyways i went with the below approach and the process was terminating if sort is not working

sort -k 1.10,1.20n -o $inputfile $outputfile 2>> error_log
pgmcc=$?

if [[ $pgmcc != 0 ]]
then
echo "FATAL ERROR, TERMINATING NOW"
fi

In this case i'm just getting the error written in error_log as sort: A write error occured while sorting.

But i want to capture error which comes on the console something like below:

vxfs: msgcnt 5980 mesg 001: V-2-1: vx_nospace - /dev/vx/dsk/drd_rootdg/tmpvol file system full (2 block extent)

Is there a way if i can achieve the above...??
No. The vxfs error message is not being written by sort; it is a diagnostic message being written to the console by the operating system. The 2>>errlog will append diagnostics written by sort to errlog, but can't capture messages written to the terminal by the operating system nor by unrelated processes.

Your system probably has a log file where error messages written to the console are saved (but if the filesystem where the log files would be written is full, the message might only appear on the screen). Where those log files are kept is system specific.
# 5  
Old 01-03-2013
You may be using the & redirection

Code:
sort -k 1.10,1.20n -o $inputfile $outputfile &>>  error_log
if [ $? -ge 0 ];then echo "SORT ERROR";exit;fi

Regards

Sorry, did not see vxfs type of message, Don Cragun answer is the one related to your problem, not mine.

Last edited by Scrutinizer; 01-03-2013 at 01:23 PM.. Reason: did not see vxfs type of message; mod: code tags
# 6  
Old 01-03-2013
Quote:
Originally Posted by mehulleo
... ... ...

sort -k 1.10,1.20n -o $inputfile $outputfile 2>> error_log

... ... ...
Sorry I didn't notice when I posted my last message ...

Note that you are asking sort to the read data from $outputfile and to write the sorted results to the file named by $inputfile. This seems backwards???

PS I'm afraid that the &>> redirection suggested by Ikaro0 won't help and won't do what I think he thinks it will do. The command:
Code:
sort ... &>>  error_log

will run sort in the background and create an empty file named error_log (if error_log didn't already exist). Output from sort will not go into error_log from this command, even if the sort -o option is not been specified.
# 7  
Old 01-03-2013
Hi Don Cragun

As I corrected my self I did not see the vxfs type of message. I thought he wanted to redirect the error message that was already correct with "2>"
The "&>" does something that is redirecting both stdout and sderr the the file, but was a bad answer cause it did not help with the problem at all, sorry.

Last edited by Ikaro0; 01-03-2013 at 02:24 PM.. Reason: Syntax
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Error handling

Hello fellow UNIX gurus :) I have a problem regarding the script below: # Variables used in this shell. power=0 # Stores squared integer total=0 # Sum of all squared integers num=0 # Stores command line arguements # Provides error handling if command line... (5 Replies)
Discussion started by: Learn4Life
5 Replies

2. Shell Programming and Scripting

Error Handling

Below code works for different databases i.e. MYSQL and ORACLE The problem is for MYSQL in Block: if ; $? taking value accordingly but in case of ORACLE $? is always taking this value as zero (0). That is the reason in Oracle it always going in else Block in any case.. :( and in case of ... (4 Replies)
Discussion started by: ambarginni
4 Replies

3. Shell Programming and Scripting

Is it Possible to sort a list of hexadecimal numbers using "sort" command?

Hello Everybody :) !!!. i have question in mind, is it possible to sort a list of hexadecimal numbers using "sort" command? (9 Replies)
Discussion started by: Kesavan
9 Replies

4. Shell Programming and Scripting

Help with Error Handling on Script

Hi, I need your guys help again. I run a script which check for some process status in a loop. when i check the process some of the process could throw an error, how can i check that inside my script. Thanks, RR (3 Replies)
Discussion started by: rrb2009
3 Replies

5. Shell Programming and Scripting

How to Sort Floating Numbers Using the Sort Command?

Hi to all. I'm trying to sort this with the Unix command sort. user1:12345678:3.5:2.5:8:1:2:3 user2:12345679:4.5:3.5:8:1:3:2 user3:12345687:5.5:2.5:6:1:3:2 user4:12345670:5.5:2.5:5:3:2:1 user5:12345671:2.5:5.5:7:2:3:1 I need to get this: user3:12345687:5.5:2.5:6:1:3:2... (7 Replies)
Discussion started by: daniel.gbaena
7 Replies

6. Linux

Command line browser with Javascript handling capability

Hi, I have a query. Do we have any command line browser utility in linux which can fulfill the following requirement: 1. Handle pages which can have javascripts 2. Can use pre-recorded user inputs (maybe stored in some input files) for automated navigation/task. I had seen such an... (2 Replies)
Discussion started by: animesh303
2 Replies

7. Shell Programming and Scripting

Error Handling

Helo Experts, I need a help in handling errors in shell script, wants my errors displayed in text file instead of command window.. My shell script is here; cd /cygdrive/s/Files for FILES in ./*.* do temp=`basename $FILES` if cp $FILES /cygdrive/r/CopyFile1/$FILES; then echo "copy... (5 Replies)
Discussion started by: CelvinSaran
5 Replies

8. UNIX for Advanced & Expert Users

sort command abort with error

Hello, I am having an application which has been ported from UNIX. I am facing a problem with sort command. It aborts with following error message when running in a Japanese locale. sort command aborts with message "A line of the input file contains more than 20480 characters." This... (0 Replies)
Discussion started by: joshi123
0 Replies

9. Shell Programming and Scripting

file handling in perl without using system command

Hi , Is there any way to achieve following using perl program (i.e without using system command). 1.system ("echo 'test' > /usr/spool/ship.csv"); 2.system ("cat /usr/ajay_test* >> /usr/spool/RAM/work/patil.csv"); 3.system("> /usr/spool/ajay.txt"); e.g for system("rm -f... (1 Reply)
Discussion started by: ajaypatil_am
1 Replies

10. Shell Programming and Scripting

File handling, getopts command in unix

I need to create a shell script having the menu with few options such as 1. Listing 2. Change permissions 3. Modify Contents 4. Delete Files 5. Exit 1. For 1. Listing: Display a special listing of files showing their date of modification and access time (side by side) along with their... (2 Replies)
Discussion started by: bab123
2 Replies
Login or Register to Ask a Question