Error Handling

We are using a korn shell script and just calling the sql scripts in the following manner


i\ /tmp/anything1.sql
i\ /tmp/anything2.sql

I want to have some error handling that writes to a log file and then moves to execute the next file. Can anyone assist on how to handle?
earngreenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MikeOM_DBACommented:
What sql flavor?

Oracle -> Use "spool" + "whenever sql error" commands
0
earngreenAuthor Commented:
Postgres
0
MikeOM_DBACommented:
Mmmm, don't know posgres. What is the "i\" part? an executable?

To check for return codes, do this:
#
exec >/tmp/anything.log
i\ /tmp/anything1.sql  >>/tmp/anything.log
if [ $? -ne 0 ]
then
  echo "!Error..."
fi
# . . .  Etc . . .

Open in new window

0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

DavidSenior Oracle Database AdministratorCommented:
k, if an error is thrown, you want it shown.  Do you need to abort subsequent steps, or allow everything to continue?  Also, can the two sql scripts shown be started in parallel?
0
earngreenAuthor Commented:
yes, I want to show the error orbjust append to a log file. Some can be run on parrallel and some cannot.
0
DavidSenior Oracle Database AdministratorCommented:
Mike's first answer works within the SQL script -- you can spool all output to a local file.  The "whenever" syntax will dictate whether the script stops or continues, and comes in both SQL and OS flavors.

I'd perhaps start with enabling a detailed trace, then to scan the alert log for errors thrown.
http://docs.oracle.com/cd/B28359_01/server.111/b28310/monitoring001.htm

You could rewrite the /i lines to redirect your SYSOUT and SYSERR away from the display and into separate files -- but that doesn't do anything about the Oracle errors, just the OS ones.
0
skullnobrainsCommented:
psql -f FILENAME 1>&2 2>/var/log/psql_error_log

the error handling will contain file names and line numbers if there are multiple queries in each file.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.