当前位置: 首页 > BASIC > 正文

 

欢迎大家加入ORACLE超级群:

 

17115662 免费解决各种ORACLE问题

 

今天跟同事聊天,同事说oswbb可以在linux平台实现自动启动了,其实要实现随OS自动启动是比较简单的,如:inittab就可以实现。

 

参考MOS文档:

How To Start OSWatcher Black Box (OSWBB) Every System Boot (文档 ID 580513.1)

 

 

1OS平台版本与OSWBB版本

[root@orcl9i ~]# lsb_release -a

LSB Version:    :core-3.0-amd64:core-3.0-ia32:core-3.0-noarch:graphics-3.0-amd64:graphics-3.0-ia32:graphics-3.0-noarch

Distributor ID: RedHatEnterpriseAS

Description:    Red Hat Enterprise Linux AS release 4 (Nahant Update 8)

Release:        4

Codename:       NahantUpdate8

 

oswbb版本为7.2

 

2,安装oswbb-service-1.1.7-1.noarch.rpm

[root@orcl9i ~]# rpm -ivh oswbb-service-1.1.7-1.noarch.rpm

Preparing…                ########################################### [100%]

   1:oswbb-service          ########################################### [100%]

下面我们来看看/etc/init.d/oswbb的内容

[oracle@orcl9i oswbb]$ cat /etc/init.d/oswbb

#!/bin/bash

########################################################################

# vim: sw=8 ts=8

#

# Init file for Oracle OSWatcher

#

# chkconfig:    2345 99 01

# description:  automatically run Oracle OSWatcher at boot time and     \

#               stop it upon system shutdown.  Attempt to gracefully    \

#               recover from a crash by moving old OSWatcher logs       \

#               to archive-<iso-date>.

########################################################################

 

########################################################################

# source function library

########################################################################

. //etc/init.d/functions

########################################################################

 

########################################################################

# Establish default values

########################################################################

# Set OSW_HOME to the directory where your OSWatcher tools are installed

OSW_HOME=’/opt/oswbb’

# Set OSW_INTERVAL to the number of seconds between collections

OSW_INTERVAL=’30’

# Set OSW_RETENTION to the number of hours logs are to be retained

OSW_RETENTION=’48’

# Set OSW_USER to the owner of the OSW_HOME directory

OSW_USER=’root’

# Set OSW_COMPRESSION to the desired compression scheme

OSW_COMPRESSION=’gzip’

# Set OSW_ARCHIVE where the logs should be stored

OSW_ARCHIVE=’archive’

########################################################################

 

########################################################################

# pull in oswbb settings

########################################################################

[ -f //etc/oswbb.conf ] && . //etc/oswbb.conf

########################################################################

 

RETVAL=0

 

########################################################################

# Some functions to make the below more readable

########################################################################

 

LOCKFILE=/var/lock/subsys/oswbb

prog=’OSWatcher’

 

########################################################################

# start: push archive dir to timestamped backup, start new collection

########################################################################

 

start()

{

        echo -n $”Starting $prog: “

        /bin/su -c //usr///libexec/oswbb-service/oswbb-helper “${OSW_USER}” && success || failure

        RETVAL=$?

        [ “$RETVAL” = 0 ] && touch ${LOCKFILE}

        echo

}

 

########################################################################

# stop: stop the service

########################################################################

 

stop()

{

        echo -n $”Stopping $prog: “

        if [ -f “${LOCKFILE}” ]; then

                /bin/su -c “

                        set -e # Exit on any error;

                        cd “${OSW_HOME}”;

                        for x in ./stopOSWbb.sh ./stopOSW.sh; do

                                if [ -x “\${x}” ]; then

                                        exec “\${x}”

                                fi

                        done

                        exit 1

                ” “${OSW_USER}” && success || failure

        else

                echo -n $”not running.”

                failure

        fi

        RETVAL=$?

        rm -f “${LOCKFILE}”

        echo

}

 

########################################################################

# restart: stop, pause, then start the collection

########################################################################

 

restart()       {

        stop

        sleep 10

        start

}

 

########################################################################

# info: Show the operational parameters

########################################################################

 

info()  {

        echo $”${prog} Settings:”

 

        echo -e $”\tOSW_ARCHIVE     =\”${OSW_ARCHIVE}\””

        echo -e $”\tOSW_COMPRESSION =\”${OSW_COMPRESSION}\””

        echo -e $”\tOSW_HOME        =\”${OSW_HOME}\””

        echo -e $”\tOSW_INTERVAL    =\”${OSW_INTERVAL}\””

        echo -e $”\tOSW_RETENTION   =\”${OSW_RETENTION}\””

        echo -e $”\tOSW_USER        =\”${OSW_USER}\””

 

        if [ -f ${LOCKFILE} ]; then

                echo -e $”\tLock file present.”

        else

                echo -e $”\tLock file not present.”

        fi

}

 

########################################################################

# Decide what to do based on first comand line arg

########################################################################

 

case “$1” in

        start)

                start

                ;;

        stop)

                stop

                ;;

        restart | reload)

                restart

                ;;

        condrestart)

                if [ -f ${LOCKFILE} ] ; then

                        restart

                fi

                ;;

        status)

                echo -n $”${prog} is “

                if [ -f “${LOCKFILE}” ]; then

                        echo $”running.”

                        RETVAL=0

                else

                        echo $”not running.”

                        RETVAL=1

                fi

                ;;

        info)

                info

                ;;

        *)

                echo $”Usage: $0 {start|stop|reload|restart|condrestart|status|info}”

                RETVAL=1

esac

exit $RETVAL

下面再来看看/usr///libexec/oswbb-service/oswbb-helper的内容

[oracle@orcl9i oswbb]$ cat /usr///libexec/oswbb-service/oswbb-helper

#!/bin/bash

########################################################################

# vim: sw=8 ts=8 filetype=bash

#

# Helper file for Oracle OSWatcher

#

########################################################################

 

########################################################################

# Establish default values

########################################################################

# Set OSW_HOME to the directory where your OSWatcher tools are installed

OSW_HOME=’/opt/oswbb’

# Set OSW_INTERVAL to the number of seconds between collections

OSW_INTERVAL=’30’

# Set OSW_RETENTION to the number of hours logs are to be retained

OSW_RETENTION=’48’

# Set OSW_USER to the owner of the OSW_HOME directory

OSW_USER=’root’

# Set OSW_COMPRESSION to the desired compression scheme

OSW_COMPRESSION=’gzip’

# Set OSW_ARCHIVE to where the output logs should be generated

OSW_ARCHIVE=’archive’

########################################################################

 

########################################################################

# pull in configuration settings

########################################################################

[ -f //etc/oswbb.conf ] && . //etc/oswbb.conf

########################################################################

 

set -e # Exit on any error;

 

cd “${OSW_HOME}”

 

mkdir -p “${OSW_ARCHIVE}”

 

for x in ./startOSWbb.sh ./startOSW.sh; do

        if [ -x “${x}” ]; then

                nohup “${x}”                                            \

                        “${OSW_INTERVAL}”                               \

                        “${OSW_RETENTION}”                              \

                        “${OSW_COMPRESSION}”                            \

                        “${OSW_ARCHIVE}”                                \

                        >”${OSW_ARCHIVE}/heartbeat 2>&1 &

                exit $?

        fi

done

 

exit 1

4,启动服务

修改oswbb中的OSW_HOMEoswbb的解压目录

[root@orcl9i ~]# cat /etc/init.d/oswbb

#!/bin/bash

########################################################################

# vim: sw=8 ts=8

#

# Init file for Oracle OSWatcher

#

# chkconfig:    2345 99 01

# description:  automatically run Oracle OSWatcher at boot time and     \

#               stop it upon system shutdown.  Attempt to gracefully    \

#               recover from a crash by moving old OSWatcher logs       \

#               to archive-<iso-date>.

########################################################################

 

########################################################################

# source function library

########################################################################

. //etc/init.d/functions

########################################################################

 

########################################################################

# Establish default values

########################################################################

# Set OSW_HOME to the directory where your OSWatcher tools are installed

#OSW_HOME=’/opt/oswbb’

OSW_HOME=’/home/oracle/oswbb’

# Set OSW_INTERVAL to the number of seconds between collections

OSW_INTERVAL=’30’

# Set OSW_RETENTION to the number of hours logs are to be retained

OSW_RETENTION=’48’

# Set OSW_USER to the owner of the OSW_HOME directory

OSW_USER=’root’

# Set OSW_COMPRESSION to the desired compression scheme

OSW_COMPRESSION=’gzip’

# Set OSW_ARCHIVE where the logs should be stored

OSW_ARCHIVE=’archive’

启动报错

[root@orcl9i ~]# /etc/init.d/oswbb start

Starting OSWatcher: //usr///libexec/oswbb-service/oswbb-helper: line 34: cd: /opt/oswbb: No such file or directory

[FAILED]

再修改下面脚本内容

[root@orcl9i ~]# vi /usr///libexec/oswbb-service/oswbb-helper

#!/bin/bash

########################################################################

# vim: sw=8 ts=8 filetype=bash

#

# Helper file for Oracle OSWatcher

#

########################################################################

 

########################################################################

# Establish default values

########################################################################

# Set OSW_HOME to the directory where your OSWatcher tools are installed

OSW_HOME=’/home/oracle/oswbb’

# Set OSW_INTERVAL to the number of seconds between collections

OSW_INTERVAL=’30’

# Set OSW_RETENTION to the number of hours logs are to be retained

OSW_RETENTION=’48’

# Set OSW_USER to the owner of the OSW_HOME directory

OSW_USER=’root’

# Set OSW_COMPRESSION to the desired compression scheme

OSW_COMPRESSION=’gzip’

# Set OSW_ARCHIVE to where the output logs should be generated

OSW_ARCHIVE=’archive’

再次启动还是报错

[root@orcl9i ~]# /etc/init.d/oswbb start

Starting OSWatcher: //usr///libexec/oswbb-service/oswbb-helper: line 45: unexpected EOF while looking for matching `”‘

[FAILED]

 

去掉

for x in ./startOSWbb.sh ./startOSW.sh; do

        if [ -x “${x}” ]; then

                nohup “${x}”                                            \

                        “${OSW_INTERVAL}”                               \

                        “${OSW_RETENTION}”                              \

                        “${OSW_COMPRESSION}”                            \

                        “${OSW_ARCHIVE}”                                \

                        >${OSW_ARCHIVE}/heartbeat 2>&1 &

                exit $?

        fi

done

再启动正常

[root@orcl9i ~]# /etc/init.d/oswbb start

Starting OSWatcher: [  OK  ]

 

总结:其实要做成自动启动是很方便的,我们只需要增加到/etc/inittab中去就可以了

下面是写成一个脚本

只在linux环境测试过

#!/bin/bash

########################################################################

# vim: sw=8 ts=8

#

# Init file for Oracle OSWatcher

#

# chkconfig:    2345 99 01

# description:  automatically run Oracle OSWatcher at boot time and     \

#               stop it upon system shutdown.  Attempt to gracefully    \

#               recover from a crash by moving old OSWatcher logs       \

#               to archive-<iso-date>.

########################################################################

 

########################################################################

# source function library

########################################################################

. //etc/init.d/functions

########################################################################

 

########################################################################

# Establish default values

########################################################################

# Set OSW_HOME to the directory where your OSWatcher tools are installed

OSW_HOME=’/home/oracle/oswbb’

# Set OSW_INTERVAL to the number of seconds between collections

OSW_INTERVAL=’30’

# Set OSW_RETENTION to the number of hours logs are to be retained

OSW_RETENTION=’48’

# Set OSW_USER to the owner of the OSW_HOME directory

OSW_USER=’oracle’

# Set OSW_COMPRESSION to the desired compression scheme

OSW_COMPRESSION=’gzip’

# Set OSW_ARCHIVE where the logs should be stored

OSW_ARCHIVE=$OSW_HOME/archive

########################################################################

 

########################################################################

# pull in oswbb settings

########################################################################

[ -f //etc/oswbb.conf ] && . //etc/oswbb.conf

########################################################################

 

RETVAL=0

 

########################################################################

# Some functions to make the below more readable

########################################################################

 

LOCKFILE=/var/lock/subsys/oswbb

prog=’OSWatcher’

 

########################################################################

# start: push archive dir to timestamped backup, start new collection

########################################################################

 

start()

{

        echo -n $”Starting $prog: “

        /bin/su -c “set -e # Exit on any error;

                   cd “${OSW_HOME}”

                   mkdir -p “${OSW_ARCHIVE}”

                   for x in ./startOSWbb.sh ./startOSW.sh; do

                           if [ -x “${x}” ]; then

                                   nohup “${x}”                                            \

                                           “${OSW_INTERVAL}”                               \

                                           “${OSW_RETENTION}”                              \

                                           “${OSW_COMPRESSION}”                            \

                                           “${OSW_ARCHIVE}”                                \

                                           >${OSW_ARCHIVE}/heartbeat 2>&1 &

                                   exit $?

                           fi

                   done                  

                   exit 1

” “${OSW_USER}” && success || failure

        RETVAL=$?

        [ “$RETVAL” = 0 ] && touch ${LOCKFILE}

        echo

}

########################################################################

# stop: stop the service

########################################################################

 

stop()

{

        echo -n $”Stopping $prog: “

        if [ -f “${LOCKFILE}” ]; then

                /bin/su -c “

                        set -e # Exit on any error;

                        cd “${OSW_HOME}”;

                        for x in ./stopOSWbb.sh ./stopOSW.sh; do

                                if [ -x “\${x}” ]; then

                                        exec “\${x}”

                                fi

                        done

                        exit 1

                ” “${OSW_USER}” && success || failure

        else

                echo -n $”not running.”

                failure

        fi

        RETVAL=$?

        rm -f “${LOCKFILE}”

        echo

}

 

########################################################################

# restart: stop, pause, then start the collection

########################################################################

 

restart()       {

        stop

        sleep 10

        start

}

 

########################################################################

# info: Show the operational parameters

########################################################################

 

info()  {

        echo $”${prog} Settings:”

 

        echo -e $”\tOSW_ARCHIVE     =\”${OSW_ARCHIVE}\””

        echo -e $”\tOSW_COMPRESSION =\”${OSW_COMPRESSION}\””

        echo -e $”\tOSW_HOME        =\”${OSW_HOME}\””

        echo -e $”\tOSW_INTERVAL    =\”${OSW_INTERVAL}\””

        echo -e $”\tOSW_RETENTION   =\”${OSW_RETENTION}\””

        echo -e $”\tOSW_USER        =\”${OSW_USER}\””

 

        if [ -f ${LOCKFILE} ]; then

                echo -e $”\tLock file present.”

        else

                echo -e $”\tLock file not present.”

        fi

}

 

########################################################################

# Decide what to do based on first comand line arg

########################################################################

 

case “$1” in

        start)

                start

                ;;

        stop)

                stop

                ;;

        restart | reload)

                restart

                ;;

        condrestart)

                if [ -f ${LOCKFILE} ] ; then

                        restart

                fi

                ;;

        status)

                echo -n $”${prog} is “

                if [ -f “${LOCKFILE}” ]; then

                        echo $”running.”

                        RETVAL=0

                else

                        echo $”not running.”

                        RETVAL=1

                fi

                ;;

        info)

                info

                ;;

        *)

                echo $”Usage: $0 {start|stop|reload|restart|condrestart|status|info}”

                RETVAL=1

esac

exit $RETVAL

 

 

oswbb在linux平台随系统自动启动:等您坐沙发呢!

发表评论

gravatar

? razz sad evil ! smile oops grin eek shock ??? cool lol mad twisted roll wink idea arrow neutral cry mrgreen

快捷键:Ctrl+Enter