Linux/unix Shell Monitoring Oracle Instance (monitor instance)

Source: Internet
Author: User

Using shell scripts to monitor and manage Oracle databases will greatly simplify the workload of DBAs, such as common monitoring of instances, monitoring of monitors, monitoring of alarm logs, backup of databases, automatic mailing of AWR report, etc. This article gives an example of using shell scripts to monitor Oracle instances under Linux.

Reference for Linux Shell:
Linux/unix calling Sql,rman script in shell script
Linux/unix passing variables between shell SQL
Linux/unix Shell calls PL/SQL

1. Monitoring Oracle Instance shell scripts

[Python]View PlainCopyprint?
  1. [Email protected]:~/dba_scripts/custom/bin> more ck_inst.sh
  2. # +-------------------------------------------------------+
  3. # + CHECK INSTANCE STATUS and SEND MAIL |
  4. # + Author:robinson |
  5. # + blog:http://blog.csdn.net/robinson_0612 |
  6. # + DESC: |
  7. # + variable x_db use to exclude some instance |
  8. # +-------------------------------------------------------+
  9. #!/bin/bash
  10. # --------------------------------------------
  11. # Set Environment vairable and define variable
  12. # --------------------------------------------
  13. If [-f ~/.bash_profile]; Then
  14. . ~/.bash_profile
  15. Fi
  16. Oratab=/etc/oratab
  17. timestamp= ' Date +%y%m%d%h%m '
  18. Mailpath=/users/robin/dba_scripts/sendemail-v1. About
  19. Log_dir=/users/robin/dba_scripts/custom/log
  20. Log_file=${log_dir}/ck_inst_$timestamp.log
  21. dbalist="[Email protected];[ Email protected] "
  22. x_db=' sybo2sz| cnqdii| Cnfo '
  23. retention=1
  24. # ----------------------
  25. # Check Instance Status
  26. # ----------------------
  27. If [-Z ' $X _db]; Then
  28. x_db=' DUMMY '
  29. Fi
  30. {
  31. echo "' Date '"
  32. echo "Oracle Database (s) Status on ' hostname '"
  33. echo "-----------------------------------------"
  34. db= ' Egrep-i ": y|:n" $ORATAB | cut-d":"-F1 | Grep-v " \#" | grep-v "\*"
  35. Pslist= ' Ps-ef | grep Pmon | Grep-v grep '
  36. Dblist= ' fori in $db, do echo $i, done | GREP-VP $X _db '
  37. For i in $dblist;
  38. echo "$pslist" | grep "[oa]*_pmon_$i" >/dev/null 2>&1
  39. if ($?)); Then
  40. echo "Oracle instance-$i: Down"
  41. Else
  42. echo "Oracle instance-$i: Up"
  43. Fi
  44. Done
  45. }|tee-a ${log_file} 2>&1
  46. # ------------------------
  47. # Send Email
  48. # ------------------------
  49. Cnt= ' Cat $LOG _file | grep down | Wc-l '
  50. If [ "$cnt"-gt 0]; Then
  51. $MAILPATH/sendemail-f [email protected]2gotrade.com-t $DBALIST-u "Instance status on ' hostname '"-O message-fil e= $LOG _file
  52. Fi
  53. # ------------------------------------------------
  54. # Removing files older than $RETENTION parameter
  55. # ------------------------------------------------
  56. Find ${log_dir}-name "ck_inst*.*"-mtime + $RETENTION-exec rm {} \;
  57. Exit
  58. [Email protected]:~/dba_scripts/custom/bin>./ck_inst.sh
  59. Fri Feb 1 :CST
  60. Oracle Database (s) Status on szdb
  61. -----------------------------------------
  62. Oracle Instance-cnbo1:up
  63. Oracle Instance-cnbotst:down
  64. Oracle Instance-cnmmbo:up
  65. Oracle Instance-mmbotst:up
  66. Oracle Instance-cnmmbobk:down
  67. Oracle Instance-ci8960u:up
  68. Oracle Instance-cnbo2:up
  69. Feb : szdb sendemail[16024]: Email was sent successfully!

2. Supplement
A, the above script is monitored according to the instance listed in/etc/oratab, can monitor multiple instances.
b, the variable x_db is used to exclude instances that do not need to be monitored, such as 3 instances are discharged from a script. You can also leave the variable blank.
C, if the value of x_db is empty, we give dummy to ensure that your DB instance name is not used dummy, otherwise filtering will not be removed.
D, monitoring scripts in the monitoring process as long as one instance is down, the entire monitoring report is sent.
D. Use the SendEmail Mail Sender program to send mail. See: The Indispensable SendEmail
E, tail clear the log that precedes the retention date that is generated during the monitoring process.

Ext.: http://blog.csdn.net/leshami/article/details/8563115

Linux/unix Shell Monitoring Oracle Instance (monitor instance)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.