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:
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.
#::-- 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!