Solved

how to handle error in bash scripting in unix

Posted on 2002-06-25
3
673 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

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…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

729 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