1.编写切割脚本

#!/bin/sh
###############################################################################################################
#Script name: cleanAlert.sh
#Script description: clean Alert Log one Day.
#Current Release Version: 1.0.0
#Script Owner: He, Haibo
#Latest editor: He, Haibo
#Support platform: Linux Platform,will not support AIX.
#Change log:
#
#
#
###############################################################################################################
DATE=`date +%Y%m%d`
cat <<EOF >/tmp/create.sql
set linesize 200
set pagesize 200
col value for a100
col name for a30
show parameter name;
select name,value from v/$diag_info;
exit;
EOF


sqlplus / as sysdba @/tmp/create.sql > /tmp/create.out


db_unique_name=`cat /tmp/create.out | grep -i "db_unique_name" | awk -F ' ' {'print $3'} | sed 's/[ /t]//g'`
ORACLE_SID=`cat /tmp/create.out | grep -i "instance_name" | awk -F ' ' {'print $3'} | sed 's/[ /t]//g'`
AlertPath=`cat /tmp/create.out | grep -i "Diag Trace" | awk -F ' ' {'print $3'} | sed 's/[ /t]//g'`

cd $AlertPath
if [ -f alert_$ORACLE_SID.log ];then
if [ -f alert_${ORACLE_SID}_$DATE.log ];then
echo "the file is exits!"
else
cp alert_$ORACLE_SID.log alert_${ORACLE_SID}_$DATE.log
> alert_$ORACLE_SID.log
fi
fi

2.加入crontab

00 00 * * * /home/oracle/cleanAlert.sh > /tmp/cleanAlert.log 2>&1

版权声明:本文为博主原创文章,未经博主允许不得转载。

Linux,oracle