Solved

how to handle error in bash scripting in unix

Posted on 2002-06-25
3
665 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

839 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