以下脚本可以通过定时任务,每天0点执行,让警告日志按照时间分类,自动保存到相应目录中。方便对每天所产生的Alart日志进行查看。

windows下脚本

rem 复制日志文件并改名,请根据SID情况修改脚本

set year=%DATE:~0,4%
set month=%DATE:~5,2%
set day=%DATE:~8,2%
copy C:appAdministratordiag dbmsorclorcl racealert_orcl.log C:appackupalert_orcl"%
year%%month%%day%".log
rem 清空日志文件
rem 下面一句是用来清空alert_orcl.log的
cd. >C:appackupalert_orcl.log
pause
Linux平台下脚本
将alert log 按天存放,每天一个alert log 文件
#!/bin/bash
DATE=`date +%Y%m%d`
cd /u01/app/oracle/diag/rdbms/orcl/orcl/trace
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
2 将alert 文件放到一个历史文件里(会清空本身的alart文件)
#!/bin/ksh
cd /u01/app/oracle/diag/rdbms/orcl/orcl/trace
if  [ -f alert_orcl.log ];  then
cat alert_orcl.log >> alert_orcl.hist  
cat /dev/null > alert_orcl.log
fi
>> 会放在文件的最后。
> 会覆盖原来的内容。
crontab -e
crontab -l
计划任务:
18 15  * * *  /u01/app/shell/masicong2  >/u01/app/alertlogbyday.log 2>&1