Solved

how to handle error in bash scripting in unix

Posted on 2002-06-25
3
664 Views
Last Modified: 2012-06-27
hi,

How do i handle an error if for example, i cannot connect to database in bash scripting in unix.

pls help!
0
Comment
Question by:megabyte78
3 Comments
 
LVL 51

Accepted Solution

by:
ahoffmann earned 50 total points
ID: 7109904
your-command-producing-error-condition
if [ $? != 0 ]; then
  echo error occured
fi
0
 

Author Comment

by:megabyte78
ID: 7109935
just to confirm, can i do something like this?

if [ sqlplus -s /nolog != 0]; then
   echo error occured
fi
0
 
LVL 38

Expert Comment

by:yuzh
ID: 7109962
what ahoffmann mean is:

sqlplus -s /nolog
if [ $? -ne 0 ] ; then
  echo error occured
fi
# $? is the return value of your last command

you can do something like the following:

if sqlplus -s /nolog ; then
   echo "ok !"
else
   echo "error occured"
fi


0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question