среда, 20 марта 2013 г.

ADRCI purge

# ADRCI purge
30 06 * * 0 ${HOME}/bin/pkg/adrci_purge/_run.sh  > /dev/null 2>> /tmp/crontab_oracle.err


$more _run.sh
#!/bin/bash

#
# Package Name:
#

tmp_string="`dirname $0`"
pkg_name="`basename ${tmp_string}`"

if [ "${pkg_name}" = "." ]; then
  tmp_string="`pwd`"
  pkg_name="`basename ${tmp_string}`"
fi


#
# Setup Environment:
#

pkg_env="${HOME}/bin/_conf/.env"
if [ ! -r "${pkg_env}" ]; then
  echo "`date +%Y.%m.%d" "%H:%M:%S` - ${pkg_name}: ERROR!!! Execution Aborted. Not Found Environment file: ${pkg_env}" >&2
  exit 2
fi

if [ -s "${pkg_env}" ]; then
  . ${pkg_env}
else
  echo "`date +%Y.%m.%d" "%H:%M:%S` - ${pkg_name}: ERROR!!! Execution Aborted. Environment file is empty: ${pkg_env}" >&2
  exit 2
fi



#
# Check Environment:
#


# Check TMP_DIR:
if [ -z "${TMP_DIR}" ]; then
  echo "`date +%Y.%m.%d" "%H:%M:%S` - ${pkg_name}: ERROR!!! Execution Aborted. Environment variable TMP_DIR not defined" >&2
  exit 2
elif [ ! -d "${TMP_DIR}" ]; then
  echo "`date +%Y.%m.%d" "%H:%M:%S` - ${pkg_name}: ERROR!!! Execution Aborted. Directory TMP_DIR not found (${TMP_DIR})" >&2
  exit 2
elif [ ! -w "${TMP_DIR}" ]; then
  echo "`date +%Y.%m.%d" "%H:%M:%S` - ${pkg_name}: ERROR!!! Execution Aborted. Directory TMP_DIR not writeable (${TMP_DIR})" >&2
  exit 2
fi


# Check BIN_DIR:
if [ -z "${BIN_DIR}" ]; then
  echo "`date +%Y.%m.%d" "%H:%M:%S` - ${pkg_name}: ERROR!!! Execution Aborted. Environment variable BIN_DIR not defined" >&2
  exit 2
elif [ ! -d "${BIN_DIR}" ]; then
  echo "`date +%Y.%m.%d" "%H:%M:%S` - ${pkg_name}: ERROR!!! Execution Aborted. Directory BIN_DIR not found (${BIN_DIR})" >&2
  exit 2
fi


# Check COMPANY_NAME:
if [ -z "${COMPANY_NAME}" ]; then
  echo "`date +%Y.%m.%d" "%H:%M:%S` - ${pkg_name}: ERROR!!! Execution Aborted. Environment variable COMPANY_NAME not defined" >&2
  exit 2
fi


# Check HOST_NAME:
if [ -z "${HOST_NAME}" ]; then
  echo "`date +%Y.%m.%d" "%H:%M:%S` - ${pkg_name}: ERROR!!! Execution Aborted. Environment variable HOST_NAME not defined" >&2
  exit 2
fi


# Check MAIL_SYSDBA:
if [ -z "${MAIL_DBA}" ]; then
  echo "`date +%Y.%m.%d" "%H:%M:%S` - ${pkg_name}: ERROR!!! Execution Aborted. Environment variable MAIL_RECIPIENTS not defined" >&2
  exit 2
fi


# Check UTL_SEND:
if [ -z "${UTL_SEND}" ]; then
  echo "`date +%Y.%m.%d" "%H:%M:%S` - ${pkg_name}: ERROR!!! Execution Aborted. Environment variable UTL_SEND not defined" >&2
  exit 2
elif [ ! -f "${UTL_SEND}" ]; then
  echo "`date +%Y.%m.%d" "%H:%M:%S` - ${pkg_name}: ERROR!!! Execution Aborted. File UTL_SEND not found (${UTL_SEND})" >&2
  exit 2
elif [ ! -x "${UTL_SEND}" ]; then
  echo "`date +%Y.%m.%d" "%H:%M:%S` - ${pkg_name}: ERROR!!! Execution Aborted. File UTL_SEND not executable (${UTL_SEND})" >&2
  exit 2
fi


# Initialize Package:

pkg_flag="`basename $0 .sh`"
run_in_progress="${TMP_DIR}/${pkg_name}_${mess}.lock"
log_file="${TMP_DIR}/${pkg_name}_${mess}.log"
prefix="${COMPANY_NAME}#${HOST_NAME} ${pkg_name}"
mess_theme="${prefix}: Error! Another process running (${run_in_progress})"

mail_recipients="$MAIL_DBA"
echo $mail_recipients

# Check Another process for running:

if [ -f ${run_in_progress} ]; then
  echo "`date +%Y.%m.%d" "%H:%M:%S` - ${pkg_name}: Error! Another process running. Remove a file ${run_in_progress}" >&2
  echo "Remove a file ${run_in_progress}" | ${BIN_DIR}/_lib/utl_send.sh "${mess_theme}" "${mail_recipients}"
  exit 2
fi



# Prevent Parallel Execution:
touch ${run_in_progress}


# Run Implementation:
${BIN_DIR}/pkg/${pkg_name}/body.sh | tee ${log_file}



# Cleanup Stop Flag:
test -r ${run_in_progress} && rm ${run_in_progress}
$




$more body.sh
#!/bin/bash


#
# Check Parameters:
#

# Package Name:
tmp_string="`dirname $0`"
pkg_name="`basename ${tmp_string}`"

if [ "${pkg_name}" = "." ]; then
  tmp_string="`pwd`"
  pkg_name="`basename ${tmp_string}`"
fi

# Check for internal call:
if [ ! $1 = '_run' ]; then
  echo "`date +%Y.%m.%d" "%H:%M:%S` - ${pkg_name}: Error! (Parameter=1) Call `basename $0` from ./_run.sh" >&2
  exit 2
fi



#
# Define local Variables:
#

# Variables:

prefix="${COMPANY_NAME}#${HOST_NAME} ${pkg_name}"
mess_theme="${prefix}: Purge trace and dump files"
temp_file=${TMP_DIR}/${pkg_name}.tmp
mess_limit="The limit ${limit_per_free}% is exceeded"

mail_recipients="$MAIL_DBA"
echo $mail_recipients

#
# Body Section:
#

${BIN_DIR}/_lib/adrci_purge.sh  > ${temp_file}

cat ${temp_file} | ${BIN_DIR}/_lib/utl_send.sh "${mess_theme}" "${mail_recipients}"



$more adrci_purge.sh
#!/bin/sh

for ADRHOME in `adrci exec="show home"`
do
    if [ $ADRHOME = "ADR" -o $ADRHOME = "Homes:" ]
    then
        continue;
    fi
    echo $ADRHOME
    adrci << EOF
         set home $ADRHOME
         echo $ADRHOME
         set control (SHORTP_POLICY = 168)
         set control (LONGP_POLICY = 720)

         # purge all tracefiles older than 2 days (2880 minutes):
         purge -age   2880 -type trace

         # purging ALERT older than 30 days
         purge -age 43200 -type ALERT

         # purging INCIDENT older than 14 days
         purge -age  20160 -type INCIDENT

         # purging TRACE older than 14 days
         purge -age  20160 -type TRACE

         # purging CDUMP older than 14 days
         purge -age  20160 -type CDUMP

         # purging HM older than 14 days
         purge -age  20160 -type HM

         show tracefile -rt
         purge
    exit
EOF
done




$more utl_send.sh
#!/bin/bash
# UNIX


# Setup Environment:
. ${HOME}/bin/_conf/.env


# Check for Message Theme:
if [ "$1" ]; then
  priv_mess_theme="$1"
else
  priv_mess_theme="No Theme"
fi



# Check For Message Recipients:
if [ "$2" ]; then
  priv_mail_recipients="$2"
else
  priv_mail_recipients=${MAIL_DEFAULT}
fi


# :
cat - | mailx -s "${priv_mess_theme}" "${priv_mail_recipients}"


Комментариев нет:

Отправить комментарий