Unix/Linux Go Back    


UNIX for Beginners Questions & Answers If you're not sure where to post a Unix or Linux question, post it here. All unix and Linux beginners welcome in this forum!

Advice on how to set up error handling

UNIX for Beginners Questions & Answers


Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 4 Weeks Ago   -   Original Discussion by SIMMS7400
SIMMS7400 SIMMS7400 is offline
Registered User
 
Join Date: Apr 2016
Last Activity: 17 November 2017, 7:24 AM EST
Posts: 143
Thanks: 35
Thanked 3 Times in 3 Posts
Advice on how to set up error handling

Hi Folks -

I want to add error handling to a portion of a *.ksh, but I'm having difficulty doing so in an easily digestible way.

Essentially, I want to echo weather it was successful or unsuccessful after each command.

Here is the code I need to add error handling to:


Code:
perl 2passdatechange.pl
sleep 60
startMaxl.sh oracle.mxl

chmod -R 775 *.*
MY_DATE_STRING=`date +%a`
if [ $MY_DATE_STRING == "Sun" ]
then
    startMaxl.sh dly05loadto_INP_cslawr.mxl
    sleep 1800
    ./sunday_cslawr.ksh
else
    sleep 60
fi

startMaxl.sh ascmon.mxl

I did add one additional step. So before the above section of code, the script tries to locate 4 text files. If any of the text fiels are not found, it should not execute the remaining commands. I've tried to capture that below as you'll see.

Below is what I tried to spin up - but as you can see, looks awfully long and unnecessary.


Code:
#::-- Scripts will not  execute if missing a AWI/GSC Data File --::#
if [[ ! "${_ERR}" = "T" ]]
then
    cd "${_DAILYSALES_BIN}"

    perl 2passdatechange.pl
    sleep 60
    startMaxl.sh Oracle_PEL.mxl $MMDD1

    _RVAL=$?
    if [ $_RVAL -eq 0 ]
    then
        echo ---------------------------------------------------------
        echo "Oracle_PEL.mxl Process : Successful"                           
        echo ---------------------------------------------------------
    else
        echo ---------------------------------------------------------
        echo "Oracle_PEL.mxl Process  Unsuccessful"                      
        echo ---------------------------------------------------------
        _ERR=T
    fi
else
    echo "1 or more AWI or GSC data file(s) does not exist"
    echo "No further processing will be executed"
fi

if [[ ! "${_ERR}" = "T" ]]
then
    chmod -R 775 *.*
    MY_DATE_STRING=`date +%a`
    if [ $MY_DATE_STRING == "Sun" ]
    then
        startMaxl.sh dly05loadto_INP_cslawr.mxl
        
        _RVAL=$?
        if [ $_RVAL -eq 0 ]
        then
            echo ---------------------------------------------------------
            echo "dly05loadto_INP_cslawr.mxl Process : Successful"                           
            echo ---------------------------------------------------------
                sleep 1800
                ./sunday_cslawr.ksh
                
                _RVAL=$?
                if [ $_RVAL -eq 0 ]
                then
                    echo ---------------------------------------------------------
                    echo "sunday_cslawr.ksh Process : Successful"                           
                    echo ---------------------------------------------------------
                else
                    echo ---------------------------------------------------------
                    echo "sunday_cslawr.ksh Process : Successful"                           
                    echo ---------------------------------------------------------
                    _ERR=T
                fi
        else
            echo ---------------------------------------------------------
            echo "dly05loadto_INP_cslawr.mxl Process  Unsuccessful"                      
            echo ---------------------------------------------------------
            _ERR=T
        fi

    else
        sleep 60
    fi
    startMaxl.sh ascmon.mxl
        _RVAL=$?
    if [ $_RVAL -eq 0 ]
    then
        echo ---------------------------------------------------------
        echo "ascmon.mxl Process : Successful"                           
        echo ---------------------------------------------------------
    else
        echo ---------------------------------------------------------
        echo "ascmon.mxl Process  Unsuccessful"                      
        echo ---------------------------------------------------------
        _ERR=T
    fi
else 
    ""
fi


Any tips would be greatly appreciated!
Sponsored Links
    #2  
Old Unix and Linux 4 Weeks Ago   -   Original Discussion by SIMMS7400
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 19 November 2017, 9:29 AM EST
Location: Aachen, Germany
Posts: 11,625
Thanks: 320
Thanked 3,617 Times in 3,322 Posts
You might define and deploy an "error handler" function to be called after every single command. Did you consider the DEBUG trap?
Sponsored Links
    #3  
Old Unix and Linux 4 Weeks Ago   -   Original Discussion by SIMMS7400
SIMMS7400 SIMMS7400 is offline
Registered User
 
Join Date: Apr 2016
Last Activity: 17 November 2017, 7:24 AM EST
Posts: 143
Thanks: 35
Thanked 3 Times in 3 Posts
Hi Rudi -

I will check that out now!

Here is what I have working for the time being - works fine. I will look at DEBUG.


Code:
echo ---------------------------------------------------------                                                                                                
echo "Execute Data Import & Export Procedures"                                         
echo ---------------------------------------------------------

#::-- Scripts will not  execute if missing a AWI/GSC Data File --::#
if [[ ! "${_ERR}" = "T" ]]
then
    cd "${_DAILYSALES_BIN}"

    perl 2passdatechange.pl 
    sleep 60
    startMaxl.sh oracle_PEL.mxl $MMDD1
    
        _RVAL=$?
        if [ $_RVAL -eq 0 ]
        then
            echo ---------------------------------------------------------                                                                                                
            echo "Oracle_PEL.mxl : Successful"                                         
            echo ---------------------------------------------------------
        else
            echo ---------------------------------------------------------                                                                                                
            echo "Oracle_PEL.mxl : Unsuccessful"                                         
            echo ---------------------------------------------------------
            _ERR=T
        fi

    if [[ ! "${_ERR}" = "T" && ${DDD} == "Sun" ]]
    then
        echo chmod -R 775 *.*
        startMaxl.sh dly05loadto_INP_cslawr.mxl
        sleep 1800
        
        _RVAL=$?
        if [ $_RVAL -eq 0 ]
        then
            echo ---------------------------------------------------------                                                                                                
            echo "dly05loadto_INP_cslawr.mxl : Successful"                                         
            echo ---------------------------------------------------------
        else
            echo ---------------------------------------------------------                                                                                                
            echo "dly05loadto_INP_cslawr.mxl : Unsuccessful"                                         
            echo ---------------------------------------------------------
            _ERR=T
        fi
            
        if [[ ! "${_ERR}" = "T" ]]
        then
        ./sunday_cslawr.ksh

            _RVAL=$?
            if [ $_RVAL -eq 0 ]
            then
                echo ---------------------------------------------------------                                                                                                
                echo "sunday_cslawr.ksh : Successful"                                         
                echo ---------------------------------------------------------
            else
                echo ---------------------------------------------------------                                                                                                
                echo "sunday_cslawr.ksh : Unsuccessful"                                         
                echo ---------------------------------------------------------
                _ERR=T
            fi
        fi
        
    fi
    sleep 60
    if [[ ! "${_ERR}" = "T" ]]
    then
    startMaxl.sh ascmon.mxl
        
        _RVAL=$?
        if [ $_RVAL -eq 0 ]
        then
            echo ---------------------------------------------------------                                                                                                
            echo "ascmon.mxl : Successful"                                         
            echo ---------------------------------------------------------
        else
            echo ---------------------------------------------------------                                                                                                
            echo "ascmon.mxl : Unsuccessful"                                         
            echo ---------------------------------------------------------
            _ERR=T
        fi
    fi
else
    echo "1 or more AWI or GSC data file(s) does not exist"
    echo "No further processing will be executed"
fi

Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
New advice on error checking rdogadin Shell Programming and Scripting 1 10-14-2013 05:42 PM
Advice regarding filesystems handling large number of files shoaibjameel123 Red Hat 2 09-20-2011 07:02 AM
C - advice how to catch some weird error alex_5161 Programming 3 04-15-2010 03:11 PM
Error Handling -pls advice sureshg_sampat Shell Programming and Scripting 2 07-12-2008 02:10 PM
Handling ftp error vivek_damodaran Shell Programming and Scripting 1 06-23-2008 11:37 PM



All times are GMT -4. The time now is 10:18 PM.