如果oracle所在硬盘空间不是很充足,则需要定时清理alert日志,否则alert会一直自增。
SHELL脚本如下,可设置crontab一天执行一次或者一小时执行一次。会把oracle软件所在硬盘将alert日志迁移到目的路径。
#!/bin/bash
#-------------------------------------------------------------
# 将oracle产生的alert日志迁移至数据硬盘
#-------------------------------------------------------------
# @author alexander
#-------------------------------------------------------------
# @time 20160105
#-------------------------------------------------------------
# 获取alert日志路径
alert_path=$1
# 获取alert日志迁移目的路径
listener_path=$2
if [[ ! -n $1 ]] || [[ ! -n $2 ]];then
echo "日志路劲和日志迁移目的路径未设置"
exit
fi
# 获取目录下所有文件函数
function ergodic(){
local files=('null')
local i=0
for file in `ls $1 | grep -E "log_[0-9]*\.xml"`
do
if [ -f $1"/"$file ]
then
files[$i]=$1"/"$file
fi
let i++;
done
# 没有alert日志文件退出脚本
if [ $i -eq 0 ]; then
exit
fi
echo ${files[@]}
}
files=`ergodic $alert_path`
for file in ${files[*]}
do
# 获取日志文件最后修改时间
modify=`stat -c %Y $file`
# 获取时间格式年-月-日
filedate=`date -d "@${modify}" +"%Y-%m-%d"`
# 获取时间格式年月日时分秒
filesec=`date -d "@${modify}" +"%Y%m%d%H%M%S"`
# 获取日志文件路径
logpath=${file%/*}
# 获取日志文件名
logname=${file##*/}
# 获取文件后缀名
logext=${file##*.}
# 判断日志存储路径是否存在,不存见创建之
if [ ! -d $2"/"$filedate ]; then
`mkdir $2"/"$filedate`
fi
# 将日志文件移动到目的路径
`mv $file $2"/"$filedate"/"$filesec"."$logext`
done