#!/bin/bash# set usage alert thresholdTHRESHOLD=85
#hostnameHOSTNAME=$(hostname)
#mail clientMAIL=/bin/mailx
# store all disk info hereEMAIL=""
for line in $(df -hP | egrep '^/dev/' | awk '{ print $6 "_:_" $5 }')do
part=$(echo "$line" | awk -F"_:_" '{ print $1 }') part_usage=$(echo "$line" | awk -F"_:_" '{ print $2 }' | cut -d'%' -f1 )
if [ $part_usage -ge $THRESHOLD -a -z "$EMAIL" ]; then EMAIL="$(date): Running out of diskspace on $HOSTNAME\n" EMAIL="$EMAIL\n$part ($part_usage%) >= (Threshold = $THRESHOLD%)"
elif [ $part_usage -ge $THRESHOLD ]; then EMAIL="$EMAIL\n$part ($part_usage%) >= (Threshold = $THRESHOLD%)" fidone
if [ -n "$EMAIL" ];then echo -e "$EMAIL" | $MAIL -s "Alert: Partition(s) almost out of diskspace on $HOSTNAME" "test@test.com test1@test.com"fi
#!/bin/bash#Alert Log Monitoring Script
ALERT_LOG_FILE=/u01/app/oracle/diag/rdbms/XXXX/trace/alert_XXXX.logEMAIL_FILE=/tmp/alert_mail.logHOSTNAME=$(hostname)#Error out if Alert Log is missingif [ ! -f $ALERT_LOG_FILE ] ; then echo "**** $ALERT_LOG_FILE FILE MISSING FROM ALERT LOG MONITOR ******" > $EMAIL_FILE cat $EMAIL_FILE|mailx -s "Alert Log Errors" test@test.com test1@test.com exit 1fiALERT_LOG_LINE_CNT_FILE=${ALERT_LOG_FILE}.ctr#First run of the script or somebody deleted it.Therefore start from zero.if [ ! -f $ALERT_LOG_LINE_CNT_FILE ] ; thenecho 0 > $ALERT_LOG_LINE_CNT_FILEfiSTORED_LINE_CTR=`cat $ALERT_LOG_LINE_CNT_FILE`ALERT_LOG_LINE_CTR=`cat $ALERT_LOG_FILE|wc -l`#check to see whether somebody has recycled alert log file.#in this case the STORED_LINE_CTR will be higher than ALERT_LOG_LINE_CTR#If so just reset STORED_LINE_CTR to 0.if [ $ALERT_LOG_LINE_CTR -lt $STORED_LINE_CTR ] ; thenSTORED_LINE_CTR=0fiLINES_TO_MONITOR=`expr $ALERT_LOG_LINE_CTR - $STORED_LINE_CTR`tail -n $LINES_TO_MONITOR $ALERT_LOG_FILE|grep -i "ora-" > /tmp/alert_mail.log#Reset line number to ctr file to skip the scanned rows in the next runecho $ALERT_LOG_LINE_CTR > $ALERT_LOG_LINE_CNT_FILE#Email only if the file is not emptyif [ -s $EMAIL_FILE ] ; then cat $EMAIL_FILE|mailx -s "$HOSTNAME - Alert Log Errors" test@test.com test1@test.comfi