SHELL SCRIPT TO PARSE THE TOTAL LOG SWITCH FROM ORACLE DATABASE ALERT LOG

If the number of log switches need to be quickly determined from the alert log file of an oracle database, this script should assist. Modify the script as per your needs and use it.

[oracle@xhydra ~]$ cat lswitchparser.sh
#!/bin/bash



#total log switches happened yesterday
y="$(date +"%Y-%m-%dT" -d "yesterday")"

#total log switches happened today
t="$(date +"%Y-%m-%dT" -d "today")"

#total log switches happened last 1 hour
l="$(date +"%Y-%m-%dT%H" -d "1 hour ago")"
while getopts y:t:l x

do
        case "${x}" in
                y)
                        egrep -A3 $y /u01/app/oracle/diag/rdbms/db9zx/db9zx/trace/alert_db9zx.log|grep "LGWR switch"|wc -l
                        ;;
                t)
                        egrep -A3 $t /u01/app/oracle/diag/rdbms/db9zx/db9zx/trace/alert_db9zx.log|grep "LGWR switch"|wc -l
                        ;;
                l)
                        egrep -A3 $l /u01/app/oracle/diag/rdbms/db9zx/db9zx/trace/alert_db9zx.log|grep "LGWR switch"|wc -l
                        ;;
                ?)
                        echo "Invalid option" >&2
                        exit 1
        esac
done

# Execute the script with options and provide any random argument number
# Below script print last 1 hour archive generation 
[oracle@xhydra ~]$ ./lswitchparser.sh -l 3
738

Leave a Reply