LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-11-2008, 07:02 AM   #1
thunder44
LQ Newbie
 
Registered: Oct 2007
Posts: 13

Rep: Reputation: 1
Check previous error status


Hello,

This statement works if there is an error within the last command in
Line 01. I have to modify the code in Line 02 so that it checks for
errors in previous statements in Line 01. I want to get the error status
for previous commands in the statement in Line 01 such as the error
status for the command 'cat $ORA_LIST_FILE'. How to do it?

Statements:
01 cat $ORA_LIST_FILE | wc -l 1> $ORA_LIST_COUNT_FILE_TMP 2>>
${ORA_LOG_FILE}
02 if [ ! $? -eq 0 ]; then
03 exit
04 fi
 
Old 02-11-2008, 08:25 AM   #2
cmnorton
Member
 
Registered: Feb 2005
Distribution: Ubuntu, CentOS
Posts: 585

Rep: Reputation: 35
$?

Even if you capture the output in an environment variable, you should be able to find the status in $?.

IMPOSSIBLE_TO_FIND_FILE=`ls this_file_is_not_here`

if [ $? -eq 0 ]; then
echo "Impossible file found."
else
echo "Impossible file not found."
fi
 
Old 02-11-2008, 09:02 AM   #3
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
The only return value available is that of the last command in a pipeline.
 
Old 02-11-2008, 10:07 AM   #4
Hobbletoe
Member
 
Registered: Sep 2004
Location: Dayton, Oh
Distribution: Linux Mint 17
Posts: 150

Rep: Reputation: 18
Your problem should go away if you skip catting the file out. Just use wc.

Code:
wc -l ${ORA_LIST_FILE} 1> $ORA_LIST_COUNT_FILE_TMP 2>>${ORA_LOG_FILE}
 
Old 02-13-2008, 06:32 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Indeed: 'useless use of cat', also, don't use
[[ ! $? -eq 0 ]]
use
[[ $? -ne 0 ]]

PS Matir is correct also
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Installing RedHat 8.0 onto Dell PowerEdge SC1425 - hdc: status error: status = 0x58 fishsponge Linux - General 0 07-11-2006 09:02 AM
Check disk status diezjc Linux - Hardware 2 04-06-2006 03:58 PM
Hi Jeremy how do i check my previous post !! hitesh_linux LQ Suggestions & Feedback 8 12-18-2004 09:29 AM
Check for status of Serial ports in any language? BongFish Programming 11 09-11-2003 01:46 AM
Check Printer Status Debby Linux - General 5 02-08-2002 08:52 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration