need to exit if report file is not found [message #591106] |
Wed, 24 July 2013 15:54 |
|
swapnabpnn
Messages: 96 Registered: December 2010
|
Member |
|
|
Hi,
I have huge unix block code.In which i am taking out part of it.In this part it sends report file after checking line count in report file.So far it is good.But I also need to add condition where if the datafile is not found then it need to exit out or else continue to process and send the email.It is to find whether datafile is existing or not.How can I write this.Can anyone please help.
function email_report {
ux2dos $REPORT_DIR/$OUTPUT_FILE > $REPORT_DIR/$REPORT_FILE
DATAFILE=`ls -t1 $REPORT_DIR/$REPORT_FILE`
rows=`wc -l ${DATAFILE} | awk '{print $1}'` # line count from the data file
rows=$((rows-1)); # remove the header row from the count
if [ ${rows} -eq 0 ]
then
result="No items were there."
else
result="Please find the attached Report"
fi
BODY=`cat<<EOF
Job Name: ${JOB_NAME}
Script: $BIN/$SCRIPT_NAME
${result}
EOF`
print "emailing reports..."
mailx -s "${JOB_NAME}" ${REPORT_EMAIL} <<- EOF
$BODY
~< ! uuencode $REPORT_DIR/$REPORT_FILE report.csv
EOF
return $?
}
Thanks
|
|
|
|
|