在solaris下面发送邮件的脚本。

发表于:2007-06-08来源:作者:点击数: 标签:
#!/bin/ksh #----------------------------------------------------------------------- #PROGRAM:CheckAlertLog.ksh #USAGE:CheckAlertLog.ksh #FUNCTION:ChecksORACLEAlertlogsandpagesincaseof #anynewerrors.SIDis Oracle databaseidentifier. #CALLEDB

#!/bin/ksh
#-----------------------------------------------------------------------
# PROGRAM:        CheckAlertLog.ksh
# USAGE:          CheckAlertLog.ksh
# FUNCTION:       Checks ORACLE Alert logs and pages in case of
#                  any new errors. SID is Oracle database identifier.
# CALLED BY:      cron

# CASCADE FILES:  $LIBDIR/pagers.txt $LIBDIR/dbinfo.txt $LIBDIR/oraErrCount_${SID}
# AUTHOR          Naresh Puri
# Date            Thu Jun  1 18:01:56 PDT 2000
#-----------------------------------------------------------------------

SID=app1                      # Oracle database identifier
ALERTDIR=/opt/oracle8i/admin/oracle/bdump                # Directory where Oracle alert file resides
FILE=alert_${SID}.log            # Oracle alert file name
MAILX=/usr/bin/mailx             # UNIX Mail Program
LIBDIR=${HOME}/zlx_scripts      # Directory where useful information is saved
LASTCOUNT=`cat $LIBDIR/oraErrCount_${SID}`  # Count of ORA- errors
                                          # detected during last program run
DBINFO=`cat $LIBDIR/dbinfo.txt`

export MAILX
export LIBDIR
export ALERTDIR

sendAlertMessage()

{
MESSAGE="**ALARM**:${SID} from ${DBINFO}:`grep "ORA-" $ALERTDIR/$FILE | tail  -1 | head -1`"
   for LIST in `egrep "DBA" $LIBDIR/pagers.txt`
   do
      EMAIL=`echo $LIST | awk -F: '{ print $2 }'`
      echo $MESSAGE | $MAILX -s "${DBINFO}:alert_log:$MESSAGE" ${EMAIL}
   done

}


probeAlertLog()

{

   # Count all Oracle errors - search for string "ORA-"
   CheckError=`grep "ORA-" $ALERTDIR/$FILE | wc -l`
   # keep a count of current errors present in the Alert file
   echo $CheckError > $LIBDIR/oraErrCount_${SID}
   # If new errors are detected mail DBA only the last ORA-error Twice
   if [ $CheckError -ne $LASTCOUNT ]
   then
         sendAlertMessage;
         sendAlertMessage;
   fi
}

probeAlertLog;
echo Suclearcase/" target="_blank" >ccessful completion $0 at `date`.

--------------------------
这个程序调用两个文件,
一个是  dbinfo.txt
定义你的数据库
61.222.44.67_app1(search)

另一个是pagers.txt
zlx:zlx@chinaunix.net  BA
zlx:[email protected]  BA

 C.Arthur 回复于:2004-02-23 20:39:46
此脚本已经过测试

原文转自:http://www.ltesting.net