http://blog.csdn.net/tianlesoftware/article/details/6195742
默认情况下alert log 只有一个文件,当积累到一定量的时候,要查看alert.log 的时候,就有点小麻烦。 只能用tail -xxx 行来查看。 所以,如果能把alert.log 按天存放,或者放到一个历史文件里。 而alert.log 只保留当天的log内容的话,这样查看就很方便了。
而且这样也有利于我们用脚本来查看alert log 中当天是否有错误发生。
一. Windows平台
windows 下是个批处理文件。 把这个批处理文件添加到计划任务,每天0点执行一下就可以了。
back_log_file.bat
rem 复制日志文件并改名,请根据SID情况修改脚本
set year=%DATE:~0,4%
set month=%DATE:~5,2%
set day=%DATE:~8,2%
copy D:/oracle/admin/orcl/bdump/alert_orcl.log D:/oracle/admin/orcl/bdump/alert_orcl"%year%%month%%day%".log
rem 清空日志文件
rem 下面一句是用来清空alert_orcl.log的
cd. >D:/oracle/admin/orcl/bdump/alert_orcl.log
二. Linux平台下
2.1 将alert文件放到一个历史文件里
#################################################
## alertlogbyday.sh
##created by tianlesoftware
## 2011-2-20
#################################################
#!/bin/ksh
cd $ORACLE_BASE/admin/SID/bdump
if [ -f alert_SID.log ]; then
cat alert_SID.log >> alert_SID.hist
cat /dev/null > alert_SID.log
fi
>> 会放在文件的最后。
> 会覆盖原来的内容。
这个shell 脚本需要在每天的0点执行
2.2 将alert log按天存放,每天一个alert log 文件
#################################################
## alertlogbyday.sh
##created by tianlesoftware
## 2011-2-20
##SID换成实际的
#################################################
#!/bin/ksh
DATE=`date +%Y%m%d`
cd $ORACLE_BASE/admin/SID/bdump
if [ -f alert_SID.log ]; then
if [ -f alert_SID _$DATE.log ]; then
echo "the file is exits!"
else
cat alert_SID.log >> alert_SID _$DATE.log
cat /dev/null > alert_SID.log
fi
fi
将脚本添加到crontb:
[oracle@qs-wg-db2 ~]$ crontab -l
00 00 * * * /u01/scripts/alertlogbyday.sh >/u01/scripts/ alertlogbyday.log 2>&1
Linux Crontab 定时任务命令详解
http://blog.csdn.net/tianlesoftware/archive/2010/02/21/5315039.aspx
[oracle@rac1 script]$ more alertlogbyday.sh
#################################################
## alertlogbyday.sh
##created by tianlesoftware
## 2013-07-29
#################################################
#!/bin/ksh
cd $ORACLE_BASE/admin/ora10g/bdump
if [ -f alert_ora10g.log ]; then
cat alert_ora10g.log >> alert_ora10g.hist
cat /dev/null > alert_ora10g.log
fi
[oracle@rac1 script]$ more alertlogbyday1.sh
#################################################
## alertlogbyday.sh
##created by tianlesoftware
## 2011-2-20
#################################################
#!/bin/ksh
DATE=`date +%Y%m%d`
cd $ORACLE_BASE/admin/ora10g/bdump
if [ -f alert_ora10g.log ]; then
if [ -f alert_ora10g_$DATE.log ]; then
echo "the file is exits!"
else
cat alert_ora10g.log >> alert_ora10g_$DATE.log
cat /dev/null > alert_ora10g.log
fi
fi
[oracle@rac1 script]$
[oracle@rac1 bdump]$ ps -ef | grep -i listener | grep -v grep
oracle 4554 1 0 14:06 ? 00:00:00 /home/oracle/db_1/bin/tnslsnr LISTENER -inherit