LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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: 6

Rep: Reputation: 0
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
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
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 10, Linux Mint 11
Posts: 148

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
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,289

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

PS Matir is correct also
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


All times are GMT -5. The time now is 11:25 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration