NinGoo.net --- Oracle DBA|MySQL DBA|数据库管理,架构,监控与性能优化

    使用stty修改终端设置

    在linux/unix平台上的sqlplus中,如果输错了字符,要想删除,习惯性的按下backspace键后,发现非但没有删除想要删掉的字符,还多出了两个字符^H。当然,我们可以同时按下ctrl+backspace键来删除,但对于习惯了用backspace来删除的用户,这样很不爽。这可以通过修改tty终端的设置来实现backspace删除功能。通过使用stty命令,就可以查看或者修改终端的按键设置。

    例如,设置backspace为删除键:

    [oracle10g@linux]$ stty erase ^h

    如果要改回使用ctrl+backspace为删除键

    [oracle10g@linux]$ stty erase ^?

    如果需要重启后自动设置终端,可以将上述命令加入到profile中。

    可以通过stty -a命令来查看所有的终端设置。下面是在linux下执行的输出:

    [oracle10g@linux]$ stty -a
    speed 38400 baud; rows 66; columns 132; line = 0;
    intr = ^C; quit = ^\; erase = ^H; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
    werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
    -parenb -parodd cs8 -hupcl -cstopb cread -clocal -crtscts
    -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel
    opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
    isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke

    其中:

    Oracle Database Internals Newsletter October 2007

    oracle database internals newsletter

    Oracle Global Customer Services的Internals Support Team主要负责为客户处理诸如Ora-600,Ora7445之类的内部错误以及block corruption等严重问题,现在他们开始制作Database Internals Newsletter来分享对于这类问题的处理经验,2007年10月份创刊号,不过是发布在metalink上的,需要有metalink帐号才能看了。

    地址:Note 460494.1

    号外:Oracle各版本最新patchset

    Oracle11gR1 for linux x86 64位版本可以下载了

    Oracle_linux_x86_64

    http://www.oracle.com/technology/software/products/database/index.html

    shell 编程之2>&1

    经常可以在一些脚本,尤其是在crontab调用时发现如下形式的命令调用

    /tmp/test.sh > /tmp/test.log 2>&1

    前半部分/tmp/test.sh > /tmp/test.log很容易理解,那么后面的2>&1是怎么回事呢?

    要解释这个问题,还是得提到文件重定向。我们知道>和<是文件重定向符。那么1和2是什么?在shell中,每个进程都和三个系统文件相关联:标准输入stdin,标准输出stdout和标准错误stderr,三个系统文件的文件描述符分别为0,1和2。所以这里2>&1的意思就是将标准错误也输出到标准输出当中。

    下面通过一个例子来展示2>&1有什么作用:

    $ cat test.sh
    t
    date

    test.sh中包含两个命令,其中t是一个不存在的命令,执行会报错,默认情况下,错误会输出到stderr。date则能正确执行,并且输出时间信息,默认输出到stdout

    ./test.sh > test1.log
    ./test.sh: line 1: t: command not found

    $ cat test1.log
    Tue Oct  9 20:51:50 CST 2007

    可以看到,date的执行结果被重定向到log文件中了,而t无法执行的错误则只打印在屏幕上。

    $ ./test.sh > test2.log 2>&1

    $ cat test2.log
    ./test.sh: line 1: t: command not found
    Tue Oct  9 20:53:44 CST 2007

    这次,stderr和stdout的内容都被重定向到log文件中了。

    实际上, > 就相当于 1> 也就是重定向标准输出,不包括标准错误。通过2>&1,就将标准错误重定向到标准输出了,那么再使用>重定向就会将标准输出和标准错误信息一同重定向了。如果只想重定向标准错误到文件中,则可以使用2> file


    常用标签:

    最新评论 | Recent comments