2006-5-19 08:59
ws_dmgy
高手帮我看看代码啊,我看不懂
cat $ALERT_FILE | awk -v last_time="$LAST_TIME" ' \
function getdate(dt)
{
mons[1]="Jan";
mons[2]="Feb";
mons[3]="Mar";
mons[4]="Apr";
mons[5]="May";
mons[6]="Jun";
mons[7]="Jul";
mons[8]="Aug";
mons[9]="Sep";
mons[10]="Oct";
mons[11]="Nov";
mons[12]="Dec";
for(i=1;i<12;i++){
if(mons[i]==$2) break;
}
aa=sprintf("%04d/%02d/%02d %s", $5, i, $3, $4);
return aa;
}
BEGIN { num=0; }
NF==5 && length($4)==8 && substr($4,3,1)==":" &&\
substr($4,6,1)==":" {
alert_time=getdate($0);
cc=0; # avoid to display caused detail errors
}
{
if(alert_time > last_time) # Optimize for speed!
{
if ( substr($0,1,4) =="ORA-" || # main()
substr($0,1,19)=="Instance terminated" ||
substr($0,1,24)=="Starting ORACLE instance" ||
substr($0,1,23)=="Shutting down instance " )
{
if(cc<1) # Get rid of detail information
{
cc++;
tm=substr(alert_time,6,14);
if(num==0){ # first time message appeared
ora_msg=$0; # save message for analyze
num++;
}
else { # merge same oracle errors!!
# only think about ORA-xxxxx, may have bug.
if(substr($0,1,9)==substr(ora_msg,1,9)) num++;
else {
if(num==1) # only one
print tm " " ora_msg;
else
print "(" num " times) " tm " " ora_msg;
num=1; # begin new merge!!
ora_msg=$0; # save compared string
}
}
}
}
} # end if(alert_time > last_time)
}
END {
if(num!=0){
if(num==1)
print tm " " ora_msg;
else
print "(" num " times) " tm " " ora_msg;
}
}' | sed 's/\"//g' >$ALERT_LOG
2006-5-19 09:00
ws_dmgy
cat $ALERT_FILE | awk -v last_time="$LAST_TIME" ' \
function getdate(dt)
{
这就看不懂了,awk -v 我知道是给变量附值,但后面怎么还有个函数,这个格式合法吗?
还有,这个函数下面写的代码好象不是SHELL内容,是不是Perl,这些内容和前面 cat $ALERT_FILE | awk -v last_time="$LAST_TIME" ' \ 有什么关系
对了,这个SHELL主要功能是检查oracle 日志中的错误信息,$ALERT_FILE是 数据库日志文件
$ALERT_FILE 内容:
Thu Dec 8 02:29:37 2005
Thread 2 advanced to log sequence 651
Thu Dec 8 02:29:37 2005
ARC1: Evaluating archive log 6 thread 2 sequence 650
Thu Dec 8 02:29:37 2005
Current log# 7 seq# 651 mem# 0: /dev/rredo_07_512m_01
Current log# 7 seq# 651 mem# 1: /dev/rredo_07_512m_02
Thu Dec 8 02:29:37 2005
ARC1: Beginning to archive log 6 thread 2 sequence 650
Creating archive destination LOG_ARCHIVE_DEST_1: '/oracle/arch164/arch_2_650.arc'
Thu Dec 8 02:29:53 2005
ARC1: Completed archiving log 6 thread 2 sequence 650
Thu Dec 8 02:31:25 2005
Thread 2 advanced to log sequence 652
Current log# 8 seq# 652 mem# 0: /dev/rredo_08_512m_01
Current log# 8 seq# 652 mem# 1: /dev/rredo_08_512m_02
Thu Dec 8 02:31:25 2005
ARC0: Evaluating archive log 7 thread 2 sequence 651
ARC0: Beginning to archive log 7 thread 2 sequence 651
Creating archive destination LOG_ARCHIVE_DEST_1: '/oracle/arch164/arch_2_651.arc'
Thu Dec 8 02:31:45 2005
ARC0: Completed archiving log 7 thread 2 sequence 651
Thu Dec 8 02:33:29 2005
Thread 2 advanced to log sequence 653
Current log# 5 seq# 653 mem# 0: /dev/rredo_05_512m_01
Current log# 5 seq# 653 mem# 1: /dev/rredo_05_512m_02