ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 【故障处理】【oerr】【grep】谨防grep“花哨”功能导致oerr工具无法使用

【故障处理】【oerr】【grep】谨防grep“花哨”功能导致oerr工具无法使用

Linux操作系统 作者:lewangx 时间:2014-01-06 10:20:29 0 删除 编辑
曾经谈到过如何使用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博客 ” ,链接:https://blog.itpub.net/27226965/viewspace-1067408/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2012-09-27

  • 博文量
    4
  • 访问量
    6439