exception case [message #590766] |
Mon, 22 July 2013 15:36 |
|
swapnabpnn
Messages: 96 Registered: December 2010
|
Member |
|
|
Hi ,
Following script is trying to email report after executing pl/sql procedure by passing commandline argument SALE_LOC while running the shell script.So far it is working fine.Issue is when by mistake commandline argument is not passed it should print error as "please give sale_loc as input parameter".How can i write this?
################################################################################
#####
SALE_LOC=$1
################################################################################
#####
# Variable Declarations
################################################################################
#####
. ~/env_vars
#JOB_NAME=" Report by Date"
REPORT_DIR=$INOUT
OUTPUT_FILE="report.txt"
REPORT_FILE="report.csv"
function email_report
{
ux2dos $REPORT_DIR/$OUTPUT_FILE > $REPORT_DIR/$REPORT_FILE
mailx -s "Report by Date " ${CONFIRMATION_EMAIL} <<- EOF
Please find the attached Report
~< ! uuencode $REPORT_DIR/$REPORT_FILE report.csv
EOF
}
# Execute the Oracle procedure.
#############################################################################
function execute_sql {
echo "Running SQL Script"
sqlplus -s ${ORACLE_CONNECT}<<- EOF
whenever sqlerror exit sql.sqlcode;
whenever oserror exit failure;
exec prddctn.Reports.report_allcntries($SALE_LOC);
EOF
return $?
}
#main
execute_sql
STATUS=$?
if [ $STATUS -eq 0 ]
then
echo "Mailing report to user"
email_report
fi
Thanks
|
|
|
|
|
Re: exception case [message #590778 is a reply to message #590774] |
Mon, 22 July 2013 16:11 |
|
Mahesh Rajendran
Messages: 10708 Registered: March 2002 Location: oracleDocoVille
|
Senior Member Account Moderator |
|
|
Right after your variable declarations.
You are only interested in the first input ($1 which is SALE_LOC).
All you do is, if there are no input parameters, exit.
Something like this or you can get fancier by checking for bogus/invalid input or whatever.
magvivek@kalyani#cat somescript
((!$#)) && echo No input parameter ! && exit 1
function execute_sql {
echo "Running SQL Script"
sqlplus -s ${ORACLE_CONNECT} <<- EOF
whenever sqlerror exit sql.sqlcode;
whenever oserror exit failure;
exec prddctn.Reports.report_allcntries($SALE_LOC);
EOF
return $?
}
magvivek@kalyani#./somescript thisInput
magvivek@kalyani#./somescript
No input parameter !
[Updated on: Mon, 22 July 2013 16:23] Report message to a moderator
|
|
|
|
|
|
|