Run level shell script to start Oracle 10g services on RedHat Enterprise Linux (RHAS 4)

by on April 10, 2008 · 9 comments

  1. #!/bin/bash
  2. #
  3. # Run level script to start Oracle 10g services on RedHat Enterprise Linux (RHAS 4)
  4. # Script should work on other UNIX like oses :)
  5. # -------------------------------------------------------------------------
  6. # Copyright (c) 2006 nixCraft project <http://cyberciti.biz/fb/>
  7. # This script is licensed under GNU GPL version 2.0 or above
  8. # Comment/suggestion: <vivek at nixCraft DOT com>
  9. # -------------------------------------------------------------------------
  10. # chkconfig: 345 91 19
  11. # description: Startup/Shutdown Oracle service
  12.  
  13. OUSER="oracle"
  14. OPATH="/home/oracle/oracle/product/10.2.0/db_1"
  15.  
  16. # check Oracle db status
  17. function chkdb_status() {
  18.  
  19. # set username
  20. SUSER="scott"
  21. # set password
  22. SPASS="123456"
  23.  
  24. sqlplus -s /nolog > /dev/null 2>&1 <<EOF
  25. whenever sqlerror exit failure
  26. connect $SUSER/$SPASS
  27. exit success
  28. EOF
  29.  
  30. if [ $? -ne 0 ]; then
  31. echo "Connection failed : DB is down"
  32. exit 1
  33. else
  34. echo "Connection succeeded : DB is up"
  35. fi
  36. }
  37.  
  38. case "$1" in
  39. start)
  40. echo "*** Starting Oracle *** "
  41. su - $OUSER -c "$OPATH/bin/lsnrctl start"
  42. su - $OUSER -c "$OPATH/bin/dbstart"
  43. ;;
  44. stop)
  45. echo "*** Stopping Oracle *** "
  46. su - $OUSER -c "$OPATH/bin/lsnrctl stop"
  47. su - $OUSER -c "$OPATH/bin/dbshut"
  48. ;;
  49. restart)
  50. $0 stop
  51. $1 start
  52. ;;
  53. isqlstart)
  54. echo "*** Starting Oracle iSQL Plus *** "
  55. su - $OUSER -c "$OPATH/bin/isqlplusctl start"
  56. echo "*** Note: You can access service at url: http://$(hostname):5560/isqlplus"
  57. ;;
  58. isqlstop)
  59. echo "*** Stopping Oracle iSQL Plus *** "
  60. su - $OUSER -c "$OPATH/bin/isqlplusctl stop"
  61. ;;
  62. emstart)
  63. echo "*** Starting Oracle Enterprise Manager 10g Database Control ***"
  64. su - $OUSER -c "$OPATH/bin/emctl start dbconsole"
  65. echo "*** Note: You can access service at url: http://$(hostname):1158/em"
  66. ;;
  67. emstop)
  68. echo "*** Stopping Oracle Enterprise Manager 10g Database Control ***"
  69. su - $OUSER -c "$OPATH/bin/emctl stop dbconsole"
  70. ;;
  71. status)
  72. echo "*** Oracle database status ***"
  73. chkdb_status
  74. ;;
  75. *)
  76. echo $"Usage: $0 {start|stop|isqlstart|isqlstop|emstart|emstop}"
  77. exit 1
  78. esac
  79. exit 0


4000+ howtos and counting! If you enjoyed this article, join 45000+ others and get free email updates!

Click here to subscribe via email.

  • Internetagentur

    Thank you … that tutorial has me very helped.

  • Pingback: Step By Step Virtual PS Install: Install Database « PSST0101

  • Thomas

    Thank you. Quite helpful. :)

  • seckin turk

    COuld you please sendm me a mail?I want to ask you which editor did you use to paste this good looking code?

    Is it html code ?

  • Nikhil

    I am using oracle 10g through command line..It gives me following error while connecting. i am trying to connect as a dba..i am suse LINUX operating system…

    SQL*PLUS:Release10.2.0.1.0- Production on Wed: Apr 15 17:26:27 2009

    Copyright(c) 1982, 2005, Oracle. All Rights Reserved.

    SQL> connect
    Enter user-name:SYS
    Enter password:123
    ERROR:
    ORA-01034: ORACLE not available.
    ORA-27121: unable to determine the size of share memory segment.
    Linux Error:13:Permission Denied

    kindly suggest me what to do?

  • WilliamG

    Hi Nikhil, I had the same problem.
    I settled with the following instructions

    pront > sqlplus /nolog
    SQL>connect / as sysdba
    SQL>startup
    SQL>quit

    pront> cd $ORACLE_HOME/bin
    pront> lsnrctl start

  • Phil Page

    The problem I am having is that although this script will start and stop oracle when run on the command line, it does not shutdown oracle at re-boot. After logging a call with RH they told me to check the status within the script by adding the following to the script
    # Source function library.
    . /etc/rc.d/init.d/functions
    and then in the status case statment
    status dbora # ie name of script

    This then returned
    [root@host init.d]# ./dbora status
    dbora dead but subsys locked
    because the status of the system is not running no attempt will be made to shut it down at boot.

    Anyone know what code is required such that status returned will be running?

  • José Mosco

    A quick search on google reveal:
    Quote
    To enable hugetlbpages, first you need 2.6 kernel, and then you need to recompile it with the following config options enabled:

    CONFIG_HUGETLB_PAGE=y
    CONFIG_HUGETLBFS=y

    or just disable hugetlb tables:

    export DISABLE_HUGETLBFS=1

    If you are doing this you need to have a lot of free RAM

    Anyway optimizing oracle is a heavy job. Take a look after limits.conf and oracle. You need to increase the number of file descriptors and a lot of other things.

    Regards

  • Anonymous

    startup pfile =’/home/oracle/$dirname/admin/pfile/initswamy.ora’ nomount;

Previous Script:

Next Script: