After more than two months of hard work, this series of blog posts is coming to an end.ArticleIt can help you in your future work and hope to have the opportunity to communicate with you technically and learn from each other, at the same time, please stay tuned to my series of blog posts on other technical topics. Finally, I would like to thank you for your support.
To put it bluntly, this blog will undertake the previous blog and enter the main logic part of the Oracle STARTUP script.
#1. The format of the/etc/oratab script is as follows:
# Myorcl1:/opt/Oracle/product/orahome: Y
# Myorcl2:/opt/Oracle/product/orahome: N
# There are many annotations at the beginning of the file, all of which start with #. These annotations need to be ignored in subsequent processing. In the useful section, each row represents an oracle instance. The same row contains three fields separated by a colon (#). The first field is the SID of oracle, the second field is the main directory of the Oracle instance. The last field indicates whether to pull the instance at the startup. If it is Y, the instance is pulled, and N is ignored.
#2. Cat outputs each row to the while loop in the form of a pipe, serves as the input, and assigns the value to the line variable. If it reaches the end of the $ oratab file, the while loop exits.
Cat $ oratab | while read line; do
#3. If the current line starts with # And follows any character, it is a description of the comment. Ignore it directly.
#4. If the data row is valid, use the awk command to split it and extract the first domain field, that is, the SID value of Oracle, which is assigned to the variable oracle_sid. If this variable is empty, ignore it directly. The continue command returns to the beginning of the loop.
Case $ line in
\#*);;
*)
Oracle_sid = 'echo $ Line | awk-F: '{print $1 }'-'
If ["$ oracle_sid" = '*']; then
Oracle_sid = ""
Continue
Fi
#5. here, we extract the last field of the $ line variable. NF indicates the number of fields in the input line of awk. In this example, the value of NF is 3, the third field of $ line is the Status field. This Sid is pulled only when the value is Y.
If ["'echo $ Line | awk-F: '{print $ NF}'-'" = "Y"]; then
#6. Use the cut command to extract the first character of oracle_sid. If the value is the plus sign (+), it is treated as ASM instance.
#7. Here, the cut command can be replaced with $ {oracle_sid: 0: 1}. 0 indicates that it starts from the first character of the variable $ oracle_sid and takes 1 character.
If ['echo $ oracle_sid | cut-B 1' = '+']; then
Inst = "ASM instance"
ORACLE_HOME = 'echo $ Line | awk-F: '{print $2 }'-'
Export ORACLE_HOME
Log = $ ORACLE_HOME/startup. Log
#8. Use the touch command to create a log file and grant the read permission.
Touch $ log
Chmod A + r $ log
Echo "processing $ inst \" $ oracle_sid \ ": Log File $ ORACLE_HOME/startup. log"
#9. Call the function to start the ASM instance, redirect the standard output to the created log file, and redirect the standard error output to the file.
Startasminst >>$ log 2 >&1
Fi
Fi
;;
Esac
Done
#10. If the operation above the execution fails, exit the script directly. The exit value is 2.
If ["$? "! = "0"]; then
Exit 2
Fi
#11. This part will re-traverse the/etc/oratab file and start the database instance. The shell technique in this section is basically the same as the above logic. Here, only the difference section is provided.
Cat $ oratab | while read line; do
Case $ line in
\#*);;
*)
Oracle_sid = 'echo $ Line | awk-F: '{print $1 }'-'
If ["$ oracle_sid" = '*']; then
Oracle_sid = ""
Continue
Fi
# Proceed only if last field is 'y '.
If ["'echo $ Line | awk-F: '{print $ NF}'-'" = "Y"]; then
#12. The difference here is that the first character for determining oracle_sid is not the plus sign (+), which indicates that the instance is a normal database instance.
If ['echo $ oracle_sid | cut-B 1 '! = '+']; Then
Inst = "database instance"
ORACLE_HOME = 'echo $ Line | awk-F: '{print $2 }'-'
Export ORACLE_HOME
Log = $ ORACLE_HOME/startup. Log
Touch $ log
Chmod A + r $ log
Echo "processing $ inst \" $ oracle_sid \ ": Log File $ ORACLE_HOME/startup. log"
Startinst> $ log 2> & 1
Fi
Fi
;;
Esac
Done
#13. This sectionCodeThe shell logic application skills are basically the same as those of the previous sections. Here I just give the difference in skills.
Cat $ oratab | while read line; do
Case $ line in
\#*);;
*)
Oracle_sid = 'echo $ Line | awk-F: '{print $1 }'-'
If ["$ oracle_sid" = '*']; then
Oracle_sid = ""
Continue
Fi
If ["'echo $ Line | awk-F: '{print $ NF}'-'" = "W"]; then
W_oracle_sid = 'echo $ Line | awk-F: '{print $1 }'-'
Cat $ oratab | while read line; do
Case $ line in
\#*);;
*)
Oracle_sid = 'echo $ Line | awk-F: '{print $1 }'-'
If ["$ oracle_sid" = '*']; then
Oracle_sid = ""
Continue
Fi
If ['echo $ oracle_sid | cut-B 1' = '+']; then
Inst = "ASM instance"
ORACLE_HOME = 'echo $ Line | awk-F: '{print $2 }'-'
If [-x $ ORACLE_HOME/bin/srvctl]; then
Count = 0
Node = 'olsnodes-l'
#14. Execute the following command and use the grep command to filter the result. Only the rows containing $ oracle_sid is running are retained. Here, $ oracle_sid replaces the variable.
Rnode = 'srvctl status ASM-N $ node | grep "$ oracle_sid is running "'
Rc = $?
#15. If the execution fails, the execution will continue.
While ["$ RC "! = "0"]; do
#16. Count = $ (count + 1) is another way to calculate numeric variables.
Count = $ (count + 1 ))
#17.-EQ indicates that $ count equals 5.
If [$ count-EQ 5]; then
$ Logmsg "error: timed out waiting on CRS to start ASM instance $ oracle_sid"
Exit $ count
Fi
$ Logmsg "waiting for Oracle CRS service to start ASM instance $ oracle_sid"
$ Logmsg "Wait $ count ."
Sleep 60
Rnode = 'srvctl status ASM-N $ node | grep "$ oracle_sid is running "'
Rc = $?
Done
Else
$ Logmsg "error: \" $ {w_oracle_sid} \ "has dependency on ASM instance \" $ {oracle_sid }\""
$ Logmsg "error: Need $ ORACLE_HOME/bin/srvctl to check this dependency"
Fi
Fi
;;
Esac
Done # innner while
Fi
;;
Esac
Done # outer while
#18. in this section of code logic, it is mainly used to process the value of W in the last field of the/etc/oratab file. It indicates that all ASM instances have been started, enter the waiting status. At this time, only the database instance can be started. From the perspective of Shell application skills, there is no much difference between the logic of this section and the previous shell skills. Here we will not give a comment on it one by one.
Cat $ oratab | while read line; do
Case $ line in
\#*);;
*)
Oracle_sid = 'echo $ Line | awk-F: '{print $1 }'-'
If ["$ oracle_sid" = '*']; then
Oracle_sid = ""
Continue
Fi
If ["'echo $ Line | awk-F: '{print $ NF}'-'" = "W"]; then
Inst = "database instance"
If ['echo $ oracle_sid | cut-B 1' = '+']; then
$ Logmsg "error :$ {inst} \" $ {oracle_sid} \ "not started"
$ Logmsg "error: Incorrect usage: 'W' not allowed for ASM instances"
Continue
Fi
ORACLE_HOME = 'echo $ Line | awk-F: '{print $2 }'-'
Export ORACLE_HOME
Log = $ ORACLE_HOME/startup. Log
Touch $ log
Chmod A + r $ log
Echo "processing $ inst \" $ oracle_sid \ ": Log File $ ORACLE_HOME/startup. log"
Startinst> $ log 2> & 1
Fi
;;
Esac
Done
It should be noted that interested readers can continue to study another shell script in the $ ORACLE_HOME/bin directory by themselves ( DbshuT ). This script is mainly used to shut down the Oracle Database Server. Its code structure and shell skills are very similar to that of this script (dbstart.