Home » Infrastructure » Unix » need to exit if report file is not found (unix)
need to exit if report file is not found [message #591106] Wed, 24 July 2013 15:54 Go to next message
Messages: 96
Registered: December 2010
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 {
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 ]
result="No items were there."
result="Please find the attached Report"
Job Name: ${JOB_NAME}

print "emailing reports..."
mailx -s "${JOB_NAME}" ${REPORT_EMAIL} <<- EOF
~< ! uuencode $REPORT_DIR/$REPORT_FILE report.csv
return $?

Re: need to exit if report file is not found [message #591151 is a reply to message #591106] Thu, 25 July 2013 03:57 Go to previous messageGo to next message
Messages: 3136
Registered: April 2005
Location: Heilbronn, Germany
Senior Member
The "check if file exists" file test operator is -e.

You might want to use "-f" though, so that a directory or device of the same name does not break stuff.

if [ -f /etc/hosts  ]
  echo "File is a regular file"
  echo "File is not regular file or does not exist"

You could also use "-s" to check if the file has non-zero size, it might be faster than the wc.

[Updated on: Thu, 25 July 2013 03:59]

Report message to a moderator

Re: need to exit if report file is not found [message #591152 is a reply to message #591106] Thu, 25 July 2013 04:16 Go to previous message
Michel Cadot
Messages: 62207
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
This question bears no real connection with Oracle database.
Please find a more appropriate forum.
The topic is locked. ./fa/448/0/
If I'm wrong, please, PM me (or report this message to a moderator, explain why you think it should be unlocked and it might be done).

Previous Topic: if record count is zero in file,need to report
Next Topic: spool error
Goto Forum:

Current Time: Thu Nov 26 08:16:02 CST 2015

Total time taken to generate the page: 0.10827 seconds