Monday 27 June 2011

Oracle WebLogic Server Basic Concepts - Domain, Admin server, Managed Server

I found this great resource to answer the following questions:

1. What is a weblogic Domain?
2. What is a Weblogic Admin Server?
3. What is a Managed Server?
4. What is a Weblogic Cluster

and many more basic conscepts of weblogic Server.

Please go to this link: Oracle WebLogic Server Basic Concepts

This will be an eye opener presentation, if you are new to Weblogic Server.

Wednesday 22 June 2011

nohup: Execute Commands After You Exit From a Shell Prompt


Most of the time you login into remote server via ssh. If you start a shell script or command and you exit (abort remote connection), the process / command will get killed. Sometime job or command takes a long time. If you are not sure when the job will finish, then it is better to leave job running in background. However, if you logout the system, the job will be stopped. What do you do?

nohup command

Answer is simple, use nohup utility which allows to run command./process or shell script that can continue running in the background after you log out from a shell:

nohup Syntax:

nohup command-name &
Where,
  • command-name : is name of shell script or command name. You can pass argument to command or a shell script.
  • & : nohup does not automatically put the command it runs in the background; you must do that explicitly, by ending the command line with an & symbol.

nohup command examples

1) Login to remote server
$ ssh user@remote.server.com
2) Execute script called pullftp.sh
# nohup pullftp.sh &
Type exit or press CTRL + D exit from remote server.
# exit
3) Find all programs and scripts with setuid bit set on, enter:
# nohup find / -xdev -type f -perm +u=s -print > out.txt &
Type exit or press CTRL + D exit from remote server.
# exit
Please note that nohup does not change the scheduling priority of COMMAND; use nice for that:
# nohup nice -n -5 ls / > out.txt &
As you can see nohup keep processes running after you exit from a shell. Read man page of nohup and nice command for more information. Please note that nohup is almost available on Solaris/BSD/Linux/UNIX variant.
Update:
# 1: As pointed out by Jason you can use at command to queue a job for later execution. For example, you can run pullftp.sh script to queue (one minute) later execution
$ echo "pullftp.sh" | at now + 1 minute
# 2: You can also use screen command for same. Brock pointed out disown shell internal command for same purpose. Here is how you can try it out:
$ pullftp.sh &
$ disown -h
$ exit

This is a complete copy from the source. 


Aditional Info: less Nohup.out

Provides you with the output of the <command&>. This is some thing similar to tail -f on a live log file. 

Monday 20 June 2011

SetDb.env - Oracle Database Key environment Settings.

 You need the following environment setting set in your linux environment so that you can start working with the Oracle DB.

ORACLE_SID=<NAME of your DB>
export ORACLE_SID
ORACLE_HOME=<complete path of your oracle home>
export ORACLE_HOME
PATH=$ORACLE_HOME/bin:$PATH
export PATH

you can either have them typed every time you log in to the linux environment or create them as an  environment file which you can execute every time you log in to your Linux Environment.

Steps as follows:
==============
1. vi <Filename>.env or <Sid_ServerName>.env
2. copy paste the below:

ORACLE_SID=<NAME of your DB>
export ORACLE_SID
ORACLE_HOME=<complete path of your oracle home>
export ORACLE_HOME
PATH=$ORACLE_HOME/bin:$PATH
export PATH

3. Replace the parameters <Values> with your Database values.
4. Save the file.
5. Make sure that you have provided execute permissions for the file.
6. Now execute the file (Source the file) as shown below:

.<Space>./<Filename>.env.

Now all your environment variables are set.

If you would like to verify the environment Variables try the following:

$ echo $ORACLE_HOME or $ORACL_SID

You should see the values as set earlier.

Note: When the above environment variables are not set most of the Database utilities will fail to work.

For example when you run sqlplus will return an error such as:

message file spl<lang>.msb not found

SP2-0750 need to set ORACLE_HOME to your ORACLE software directory 


Reference Source: sqlplus not initializing in linux (Oracle Forum)


How to Make Oracle Database Start and Shutdown Automatically - Linux

The automatic startup and shutdown of the Oracle database can be achieved with the files dbstart and dbshut both provided by Oracle.

These files rely on the existance of the file /etc/oratab to work (although by altering the dbshut and dbstart files this can be moved).


The file oratab is used by ORACLE utilities (DbStart and DbShut).  It is created by root.sh and updated by the Database Configuration Assistant when creating a database.

The format of the /etc/oratab file is as follows: 


SID:ORACLE_HOME:AUTO

An example:


orcl:/home/oracle/7.3.3.0.0:Y  -- 'Y' -- To Start Automatically
leaveup:/home/oracle/7.3.2.1.0:N -- 'N' -- Not to start Automatically.
 
This is not it, there is more to it. The above will work only when the DbStart and DbShut scripts are run during the startup of the linux system. Please read on:



init.d & rc.d

To start and stop the database when the machine comes up and goes down by modifying the startup routines for the Linux machine. This is quite easy, although I should point out here that this may change depending on which flavour of Linux (slackware, debian, redhat, etc). I will show examples which work for Redhat Linux 5.0. To modify these for your own flavour of Linux, please see your Linux documentation sets. (Although it should hold true for any Sys V type UNIX).
Firstly, we need to create the script which will run dbshut and dbstart in the /etc/rc.d/init.d directory.

Create the following file as /etc/rc.d/init.d/OracleDB:

#!/bin/sh
# chkconfig: 345 99 10
# description: Oracle auto start-stop script.
#
# Set ORA_HOME to be equivalent to the $ORACLE_HOME
# from which you wish to execute dbstart and dbshut;
#
# Set ORA_OWNER to the user id of the owner of the
# Oracle database in ORA_HOME.

ORA_HOME=<Oracle Home>
ORA_OWNER=oracle

if [ ! -f $ORA_HOME/bin/dbstart ]
then
    echo "Oracle startup: cannot start"
    exit
fi

case "$1" in
   'start')
        # Start the Oracle databases:
        # The following command assumes that the oracle login
        # will not prompt the user for any values
        su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start"
        su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart $ORA_HOME"
        touch /var/lock/subsys/dbora
        ;;
    'stop')
        # Stop the Oracle databases:
        # The following command assumes that the oracle login
        # will not prompt the user for any values
        su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut $ORA_HOME"
        su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop"
        rm -f /var/lock/subsys/dbora
        ;;
esac




After checking the correctness of the above script, This script needs to be linked to the Linux runlevel directories.

The following commands will ensure that the databases will come up in runlevels 3,4 and 5:



$ ln -s /etc/rc.d/init.d/OracleDB /etc/rc.d/rc3.d/S99OracleDB


$ ln -s /etc/rc.d/init.d/OracleDB /etc/rc.d/rc4.d/S99OracleDB
$ ln -s /etc/rc.d/init.d/OracleDB /etc/rc.d/rc5.d/S99OracleDB





The following commands will ensure that the databases will shut down in runlevels 0,1,2 and 6:





$ ln -s /etc/rc.d/init.d/OracleDB /etc/rc.d/rc0.d/K10OracleDB          # Halting
$ ln -s /etc/rc.d/init.d/OracleDB /etc/rc.d/rc1.d/K10OracleDB
$ ln -s /etc/rc.d/init.d/OracleDB /etc/rc.d/rc2.d/K10OracleDB
$ ln -s /etc/rc.d/init.d/OracleDB /etc/rc.d/rc6.d/K10OracleDB        # Rebooting




 Reference: Oracle Database HOWTO