【故障處理】【oerr】【grep】謹防grep“花哨”功能導致oerr工具無法使用

secooler發表於2009-08-21
曾經談到過如何使用grep命令實現一個“花哨”效果:《【Shell】grep命令在結果集中顯示綠色的字元》http://space.itpub.net/519536/viewspace-609790

但是這個“花哨”的做法會導致Oracle的oerr命令失效!!一定要注意哦。

1.來看一下這個錯誤現象
$ oerr ora 7445
/oracle/app/oracle/product/10.2.0/db_1/bin/oerr: line 73: 32mora: command not found
oerr: Invalid facilities entry 'ora:rdbms:*:'

2.經過了一段時間排查之後,縱慾發現原來元兇就在這個花哨的功能(主要是GREP_OPTIONS變數設定導致的指令碼執行問題)
export GREP_OPTIONS='--color=always'
export GREP_COLOR='1;32'

3.使用unset命令取消變數GREP_OPTIONS的設定
$ unset GREP_OPTIONS
$ oerr ora 7445
07445, 00000, "exception encountered: core dump [%s] [%s] [%s] [%s] [%s] [%s]"
// *Cause: An OS exception occurred which should result in the creation of a
//         core file.  This is an internal error.
// *Action: Contact your customer support representative.

OK,到此oerr就可以正常使用了,小故障處理完畢,難道魚和熊掌真的不能同時擁有麼???請繼續往瞧……

4.魚和熊掌兼而有之的策略(目的:既可以使用oerr命令,又可以讓grep對關鍵字加亮顯示)
其實方法很簡單,換一種方式使用grep命令,就是加一個附加引數--color實現這個“花哨”的功能
為了防止每次使用都要敲這個選項,可以像我一樣設定一個同名,這樣之後就可以魚和熊掌都吃掉了。(這種方法預設的染色時粉紅色滴~~~)
alias grep='grep --color'

5.如果有同學像我一樣很喜歡深入研究“問題and故障”的話,有沒有問問自己,導致oerr不可用的原因在哪裡呢?
我來拋個磚ing
方法:
設定GREP_OPTIONS變數和取消這個變數兩種情況下使用"sh -x oerr ora 7445"比較一下執行過程就能發現問題了

【附】附一下兩種方法執行的過程,很瞭解問題原因的同學可以到此飄過了~~~~~
1)設定GREP_OPTIONS變數,導致錯誤的執行過程如下
ora10g@testdb183 /home/oracle$ export GREP_OPTIONS='--color=always'
ora10g@testdb183 /home/oracle$ sh -x oerr ora 7445
+ '[' '' = T ']'
+ '[' '!' /oracle/app/oracle/product/10.2.0/db_1 ']'
+ LC_ALL=C
+ export LC_ALL
+ Facilities_File=/oracle/app/oracle/product/10.2.0/db_1/lib/facility.lis
+ '[' 2 '!=' 2 ']'
+ Facility=ora
+ Code=7445
++ grep -i '^ora:' /oracle/app/oracle/product/10.2.0/db_1/lib/facility.lis
+ Fac_Info='ora:rdbms:*:'
+ '[' 0 -ne 0 ']'
++ echo 'ora:rdbms:*:'
++ awk -F: '{
                if (index ($3, "*") == 0)
                        printf ("Facility=%s\n", $3);
                else
                        printf ("Facility=%s\n", $1);
                printf ("Component=%s\n", $2);
                }'
+ eval 'Facility=ora' 'Component=rdbms'
++ Facility='
ora 'Component=rdbms'
/oracle/app/oracle/product/10.2.0/db_1/bin/oerr: line 73: 31mora: command not found
+ '[' -z ' -z '' ']'
+ echo 'oerr: Invalid facilities entry '\''ora:rdbms:*:'\'''
oerr: Invalid facilities entry 'ora:rdbms:*:'
+ exit 1

2)取消GREP_OPTIONS變數,正常執行過程如下
ora10g@testdb183 /home/oracle$ unset GREP_OPTIONS
ora10g@testdb183 /home/oracle$ sh -x oerr ora 7445
+ '[' '' = T ']'
+ '[' '!' /oracle/app/oracle/product/10.2.0/db_1 ']'
+ LC_ALL=C
+ export LC_ALL
+ Facilities_File=/oracle/app/oracle/product/10.2.0/db_1/lib/facility.lis
+ '[' 2 '!=' 2 ']'
+ Facility=ora
+ Code=7445
++ grep -i '^ora:' /oracle/app/oracle/product/10.2.0/db_1/lib/facility.lis
+ Fac_Info='ora:rdbms:*:'
+ '[' 0 -ne 0 ']'
++ echo 'ora:rdbms:*:'
++ awk -F: '{
                if (index ($3, "*") == 0)
                        printf ("Facility=%s\n", $3);
                else
                        printf ("Facility=%s\n", $1);
                printf ("Component=%s\n", $2);
                }'
+ eval Facility=ora Component=rdbms
++ Facility=ora
++ Component=rdbms
+ '[' -z ora -o -z rdbms ']'
+ Msg_File=/oracle/app/oracle/product/10.2.0/db_1/rdbms/mesg/oraus.msg
+ '[' '!' -r /oracle/app/oracle/product/10.2.0/db_1/rdbms/mesg/oraus.msg ']'
+ awk 'BEGIN { found = 0; }
        /^[0]*7445/     { found = 1; print ; next;}
        /^\/\//         { if (found) { print; } next; }
                        { if (found) { exit; } }' /oracle/app/oracle/product/10.2.0/db_1/rdbms/mesg/oraus.msg
07445, 00000, "exception encountered: core dump [%s] [%s] [%s] [%s] [%s] [%s]"
// *Cause: An OS exception occurred which should result in the creation of a
//         core file.  This is an internal error.
// *Action: Contact your customer support representative.
+ exit 0

3)細心你可能已經發現其中的不同,問題出現在取“Facility”的時候,單獨擷取一下,加深印象
報錯的情況:
+ eval 'Facility=ora' 'Component=rdbms'
++ Facility='
ora 'Component=rdbms'
/oracle/app/oracle/product/10.2.0/db_1/bin/oerr: line 73: 31mora: command not found

正常的情況:
+ eval Facility=ora Component=rdbms
++ Facility=ora
++ Component=rdbms
+ '[' -z ora -o -z rdbms ']'
+ Msg_File=/oracle/app/oracle/product/10.2.0/db_1/rdbms/mesg/oraus.msg

就到這裡,休息,休息一下……

-- The End --

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/519536/viewspace-612901/,如需轉載,請註明出處,否則將追究法律責任。

相關文章