# Clean system audit
06 04 * * * ${HOME}/bin/pkg/clean_sys_audit/_run.sh 1 > /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
# Check Parameters:
if [ $1 ]; then
retention_period=$1
else
echo "`date +%Y.%m.%d" "%H:%M:%S` - ${pkg_name}: Error! (Parameter=2). Call `basename $0`" >&2
exit 2
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 ORACLE_USER:
if [ -z "${ORA_USER}" ]; then
echo "`date +%Y.%m.%d" "%H:%M:%S` - ${pkg_name}: ERROR!!! Execution Aborted. Environment variable ORA_USER not defined" >&2
exit 2
else
ora_user=${ORA_USER}
fi
# Check ORACLE_BASE:
if [ -z "${ORACLE_BASE}" ]; then
echo "`date +%Y.%m.%d" "%H:%M:%S` - ${pkg_name}: ERROR!!! Execution Aborted. Environment variable ORACLE_BASE not defined" >&2
exit 2
else
oracle_base=${ORACLE_BASE}
fi
# Check ORACLE_HOME:
if [ -z "${ORACLE_HOME}" ]; then
echo "`date +%Y.%m.%d" "%H:%M:%S` - ${pkg_name}: ERROR!!! Execution Aborted. Environment variable ORACLE_HOME not defined" >&2
exit 2
elif [ ! -d "${ORACLE_HOME}" ]; then
echo "`date +%Y.%m.%d" "%H:%M:%S` - ${pkg_name}: ERROR!!! Execution Aborted. Directory ORACLE_HOME not found (${ORACLE_HOME})" >&2
exit 2
fi
# 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_RECIPIENTS:
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}_${oracle_sid}.lock
log_file=${TMP_DIR}/${pkg_name}_${oracle_sid}.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 "${pkg_flag}" "${retention_period}" | tee ${log_file}
# Send E-Mail:
# mess_theme="${host_name}(${oracle_sid}): ${mess_header}"
# cat ${log_file} | ${BIN_DIR}/_lib/utl_send.sh "${mess_theme}" "${mail_recipients}"
# 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
# Check For:
if [ $2 ]; then
retention_period=$2
else
echo "`date +%Y.%m.%d" "%H:%M:%S` - ${pkg_name}: Error! (Parameter=3) Call `basename $0` With 3-d parameter" >&2
exit 2
fi
#
# Define local variables:
#
# Variables:
host_name=${HOST_NAME}
oracle_sid=${ORACLE_SID}
mail_recipients="$MAIL_DBA"
sys_audit_dir=${ORACLE_HOME}/rdbms/audit/
echo "`date +%T` Check directory for system audit: (${sys_audit_dir})"
if [ -r ${sys_audit_dir} ]; then
echo "system audit dir done."
${FIND_UTL} /u01/app/oradb/product/11.2.0.3/dbhome_1/rdbms/audit/ -type f -name "*_ora\_*\_*.aud" -mtime +${retention_period} -print -exec ls -l {} \;
${FIND_UTL} /u01/app/oradb/product/11.2.0.3/dbhome_1/rdbms/audit/ -type f -name "*_ora\_*\_*.aud" -mtime +${retention_period} -print -exec rm {} \;
else
loc_mess_theme="${host_name}(${oracle_sid})-${pkg_name}: Error! Not Found Directory for Clean system audit"
loc_mess_body="Not exist directory: ${sys_audit_dir}"
echo "${loc_mess_body}" | ${BIN_DIR}/_lib/utl_send.sh "${loc_mess_theme}" "${mail_recipients}"
echo " - Error!"
exit
fi
$
Для очистки аудита экземпляра ASM все также, только пути будут другие
и запускать нужно crontab из под пользователя oragrid:
#
# Define local variables:
#
# Variables:
host_name=${HOST_NAME}
oracle_sid=${ORACLE_SID}
mail_recipients="$MAIL_DBA"
asm_audit_dir=${ORACLE_HOME}/rdbms/audit/
echo "`date +%T` Check directory for asm audit: (${asm_audit_dir})"
if [ -r ${asm_audit_dir} ]; then
echo "asm audit ASM dir done."
${FIND_UTL} /u01/app/11.2.0.3/grid/rdbms/audit/ -type f -name "*_ora\_*\_*.aud" -mtime +${retention_period} -print -exec ls -l {}
\;
${FIND_UTL} /u01/app/11.2.0.3/grid/rdbms/audit/ -type f -name "*_ora\_*\_*.aud" -mtime +${retention_period} -print -exec rm -f {}
\;
else
loc_mess_theme="${host_name}(${oracle_sid})-${pkg_name}: Error! Not Found Directory for Clean asm audit"
loc_mess_body="Not exist directory: ${asm_audit_dir}"
echo "${loc_mess_body}" | ${BIN_DIR}/_lib/utl_send.sh "${loc_mess_theme}" "${mail_recipients}"
echo " - Error!"
exit
fi
06 04 * * * ${HOME}/bin/pkg/clean_sys_audit/_run.sh 1 > /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
# Check Parameters:
if [ $1 ]; then
retention_period=$1
else
echo "`date +%Y.%m.%d" "%H:%M:%S` - ${pkg_name}: Error! (Parameter=2). Call `basename $0`
exit 2
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 ORACLE_USER:
if [ -z "${ORA_USER}" ]; then
echo "`date +%Y.%m.%d" "%H:%M:%S` - ${pkg_name}: ERROR!!! Execution Aborted. Environment variable ORA_USER not defined" >&2
exit 2
else
ora_user=${ORA_USER}
fi
# Check ORACLE_BASE:
if [ -z "${ORACLE_BASE}" ]; then
echo "`date +%Y.%m.%d" "%H:%M:%S` - ${pkg_name}: ERROR!!! Execution Aborted. Environment variable ORACLE_BASE not defined" >&2
exit 2
else
oracle_base=${ORACLE_BASE}
fi
# Check ORACLE_HOME:
if [ -z "${ORACLE_HOME}" ]; then
echo "`date +%Y.%m.%d" "%H:%M:%S` - ${pkg_name}: ERROR!!! Execution Aborted. Environment variable ORACLE_HOME not defined" >&2
exit 2
elif [ ! -d "${ORACLE_HOME}" ]; then
echo "`date +%Y.%m.%d" "%H:%M:%S` - ${pkg_name}: ERROR!!! Execution Aborted. Directory ORACLE_HOME not found (${ORACLE_HOME})" >&2
exit 2
fi
# 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_RECIPIENTS:
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}_${oracle_sid}.lock
log_file=${TMP_DIR}/${pkg_name}_${oracle_sid}.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 "${pkg_flag}" "${retention_period}" | tee ${log_file}
# Send E-Mail:
# mess_theme="${host_name}(${oracle_sid}): ${mess_header}"
# cat ${log_file} | ${BIN_DIR}/_lib/utl_send.sh "${mess_theme}" "${mail_recipients}"
# 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
# Check For
if [ $2 ]; then
retention_period=$2
else
echo "`date +%Y.%m.%d" "%H:%M:%S` - ${pkg_name}: Error! (Parameter=3) Call `basename $0` With 3-d parameter" >&2
exit 2
fi
#
# Define local variables:
#
# Variables:
host_name=${HOST_NAME}
oracle_sid=${ORACLE_SID}
mail_recipients="$MAIL_DBA"
sys_audit_dir=${ORACLE_HOME}/rdbms/audit/
echo "`date +%T` Check directory for system audit: (${sys_audit_dir})"
if [ -r ${sys_audit_dir} ]; then
echo "system audit dir done."
${FIND_UTL} /u01/app/oradb/product/11.2.0.3/dbhome_1/rdbms/audit/ -type f -name "*_ora\_*\_*.aud" -mtime +${retention_period} -print -exec ls -l {} \;
${FIND_UTL} /u01/app/oradb/product/11.2.0.3/dbhome_1/rdbms/audit/ -type f -name "*_ora\_*\_*.aud" -mtime +${retention_period} -print -exec rm {} \;
else
loc_mess_theme="${host_name}(${oracle_sid})-${pkg_name}: Error! Not Found Directory for Clean system audit"
loc_mess_body="Not exist directory: ${sys_audit_dir}"
echo "${loc_mess_body}" | ${BIN_DIR}/_lib/utl_send.sh "${loc_mess_theme}" "${mail_recipients}"
echo " - Error!"
exit
fi
$
# Define local variables:
#
# Variables:
host_name=${HOST_NAME}
oracle_sid=${ORACLE_SID}
mail_recipients="$MAIL_DBA"
asm_audit_dir=${ORACLE_HOME}/rdbms/audit/
echo "`date +%T` Check directory for asm audit: (${asm_audit_dir})"
if [ -r ${asm_audit_dir} ]; then
echo "asm audit ASM dir done."
${FIND_UTL} /u01/app/11.2.0.3/grid/rdbms/audit/ -type f -name "*_ora\_*\_*.aud" -mtime +${retention_period} -print -exec ls -l {}
\;
${FIND_UTL} /u01/app/11.2.0.3/grid/rdbms/audit/ -type f -name "*_ora\_*\_*.aud" -mtime +${retention_period} -print -exec rm -f {}
\;
else
loc_mess_theme="${host_name}(${oracle_sid})-${pkg_name}: Error! Not Found Directory for Clean asm audit"
loc_mess_body="Not exist directory: ${asm_audit_dir}"
echo "${loc_mess_body}" | ${BIN_DIR}/_lib/utl_send.sh "${loc_mess_theme}" "${mail_recipients}"
echo " - Error!"
exit
fi
Комментариев нет:
Отправить комментарий