Status of the second to last command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Status of the second to last command
# 1  
Old 04-13-2006
Question Status of the second to last command

Below is a chuck of a shell script I have written. The problem I am having is with the test section. I want to test the status of the f60gen command but since I'm running the output of the f60gen command into tee, the test command is actually testing "tee" and not "f60gen". Is there a way to test the second to last command? If not, how can I make this work?

$ORACLE_HOME/bin/f60gen module=$PLL_FILE \
userid=apps/$APPS_PWD \
output_file=$PLX_FILE \
module_type=library \
batch=yes \
compile_all=special | tee -a $LOG_FILE 2>&1

if [ $? = 0 ]; then
log_msg "Successfully generated $PLX_FILE"
# 2  
Old 04-13-2006
Why can't you test for your return code before you do the compile_all?

$ORACLE_HOME/bin/f60gen

if [[ $? != 0 ]]; then
print "F60gen failed" | tee -a $LOG_FILE
fi
# 3  
Old 04-13-2006
I can't do that because "compile=all" is an option for the f60gen command.
I think I found a way though. I just redirected the output from the command to a tempfile then I set a variable = $?.
I can then recall and test the value later and I also can tee tempfile into my proper logfile.

It works.
# 4  
Old 04-13-2006
Rather than creating a temp file that needs to be cleaned up afterward, you can do the same thing as follows:
Code:
{
    f60gen ...
    print variable=$?
} | while read LINE
do
    case $LINE in
        variable*)
            if [[ ${LINE#*=} -gt 0 ]]
            then
                ... report error ...
            fi
        ;;
    esac
done

# 5  
Old 04-13-2006
I have used a ksh coprocess for stuff like this. See exit status of command in a pipe line for an example. But r2007 presented an arguably better solution in Pipelining.
# 6  
Old 04-13-2006
you can use switch command if you want it also.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Exit Status of Command

Hi All, I am doing an export and import (datapump) of 4 schema. I know we can do an export of 4 schema in one command. But just want to know how to check the exit status if i do the export/import of 4 schema in different commands in background. Please suggest. Thanks, Mani (1 Reply)
Discussion started by: pvmanikandan
1 Replies

2. UNIX for Dummies Questions & Answers

Exit Status Of Find Command

Hello All, I am trying to capture the exit status of find command and want to delete the files only when it is successful. But it is always returning me as success even if the pattern of that file doesn't exist in the current directory. please help, checked manual page but couldn't able to figure... (6 Replies)
Discussion started by: Ariean
6 Replies

3. UNIX for Dummies Questions & Answers

Check the exist status of the cd command

Hi, As in scripting , some cd commands getting failed, so we do check the exist status as 0 or 1. But every time we call to function for it. But does any single line exist will do the job with || , && ? i.e ls -l Logs cd Logss | exit echo hias Logss is not exist , Before printing "hi" we... (5 Replies)
Discussion started by: posix
5 Replies

4. UNIX for Advanced & Expert Users

Equivalents of tee command to find exit status of command

Hi, Want to log the output of command & check the exit status to find whether it succeeded or failed. > ls abc ls: abc: No such file or directory > echo $? 1 > ls abc 2>&1 | tee log ls: abc: No such file or directory > echo $? 0 Tee commands changes my exit status to be always... (7 Replies)
Discussion started by: vibhor_agarwali
7 Replies

5. Shell Programming and Scripting

last command status problem

Hi there is below code in my code , i did not understand what does it mean RC=0 RC=$(( RC | $? )) Please help me regarding this ---------- Post updated at 02:22 AM ---------- Previous update was at 01:46 AM ---------- Below is more example of the code (2 Replies)
Discussion started by: aishsimplesweet
2 Replies

6. Shell Programming and Scripting

returning status of a command

Hello gurus, Tired of using $? to view the execution status of the previous command. how can I get the status directly? definitely this is not working, if ] then fi (6 Replies)
Discussion started by: biglau
6 Replies

7. UNIX for Dummies Questions & Answers

How to know the status of a Command?

Hi i have done a copy operation (Storing one content of a file to another) For example : cp Fileone Filetwo Now is it possible to know the status of the execution of that command ?? Without manually checking the Filetwo contents ?? Thanks in advance . (5 Replies)
Discussion started by: Ravi Pavanv
5 Replies

8. AIX

Tape status command

We sometime run backups to tape in the background using the cron. Is there a command that will show me how fast the information is being written and or how much data has been written? I know if we enter the information via the command prompt or smit it shows the speed and amount written. (2 Replies)
Discussion started by: daveisme
2 Replies

9. Shell Programming and Scripting

Getting the exit status of a remote command

Hi to everyone. How can I get the exit status from a remote command executed with rexec? :eek: machine A has RedHat Linux 9 and the remote machine B has SCO UNIX. Code: rexec -l user -p password host sh /u/files/scripts/seq_cal.sh 2006 08 I want the exit status returned by... (1 Reply)
Discussion started by: zoonalex
1 Replies

10. Shell Programming and Scripting

Status code of last command execution

Hello people, I am using KSH and inside my script I do a cksum and check the status code to see whether the command sucessfully. Here even though the cksum fails due to file not existing the status returned is still 0 because the awk command worked fine. How do I capture just the status of the... (1 Reply)
Discussion started by: tipsy
1 Replies
Login or Register to Ask a Question