关于linux:Linux上清理oracle-listenerlog文件脚本

33次阅读

共计 1551 个字符,预计需要花费 4 分钟才能阅读完成。

Linux 上清理 oracle listener.log 文件脚本,配合 crontab 定时清理大于 1000MB 的 listener.log

#!/bin/bash
# This script is used to clean up Oracle Database listener.log on Linux
# Please use the Oracle DB installation user(such as oracle) to execute the script
# Originally written by Xander.Cui
# Use two methods to obtain the absolute path of listener.log, only for detection.
# 2. Obtain the standard listener.log file name
# export listenerlog=$ORACLE_BASE/diag/tnslsnr/$(hostname)/listener/trace/listener.log
# export listenerlogbak=$listenerlog-$DateMark
source ~/.bash_profile
export DateMark=$(date +'%Y%m%d')
export DT=$(date +'%F %T')
# Check if the log directory exists, create it if it does not exist
export logdir=~/log
export checklog=$logdir/listenerlog_check.log
if [! -d $logdir]; then
    mkdir -p $logdir
    echo "$DT Checked: Created $logdir" >$checklog
fi
# 1. Obtain listener.log through lsnrctl status
export xmlfile=$(lsnrctl status | grep "log.xml" | awk '{print $4}')
export prefixlog=${xmlfile%%/alert*}
export listenerfile=$prefixlog/trace/listener.log
export listenerfilebak=$listenerfile-$DateMark
# Calculate the size of the listener.log file in MB, Use the file name obtained by method 1
export logsizemb=$(du -sm $listenerfile | awk '{print $1}')
# Operating listener.log file
if [$logsizemb -gt 1000]; then
    echo "*************** Moved **************
    $DT Checked: Backup Logfile $listenerfile to $listenerfilebak.tar.gz
    " >>$checklog
    mv $listenerfile $listenerfilebak;tar -zcPf $listenerfilebak.tar.gz $listenerfilebak --remove-files
else
    echo "$DT Checked: Logfile($listenerfile) Size < 1000 MB, Do nothing." >>$checklog
fi
# End

应用命令增加定时工作

(crontab -l | grep -v check_listenerlog) | crontab
(crontab -l ; echo "0 18 * * * bash ~/scripts/check_listenerlog.sh") | crontab

正文完
 0