<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-314  評論-209  文章-0  trackbacks-0
    測試平臺:RHEL4.5

    一、最簡單的shell里調用sqlplus.


    $ vi test1.sh

    #!/bin/bash
    sqlplus -S /nolog > result.log <<EOF
    set heading off feedback off pagesize 0 verify off echo off
    conn u_test/iamwangnc
    select * from tab;
    exit
    EOF

    $ chmod +x test1.sh
    $ ./test1.sh

    二、把sqlplus執行結果傳遞給shell方法一

    注意sqlplus段使用老板鍵`了, 賦變量的等號兩側不能有空格.

    $ vi test2.sh

    #!/bin/bash
    VALUE=`sqlplus -S /nolog <<EOF
    set heading off feedback off pagesize 0 verify off echo off numwidth 4
    conn u_test/iamwangnc
    select count(*) from tab;
    exit
    EOF`
    if [ "$VALUE" -gt 0 ]; then
            echo "The number of rows is $VALUE."
            exit 0
    else
            echo "There is no row in the table."
    fi

    $ chmod +x test2.sh
    $ ./test2.sh

    三、把sqlplus執行結果傳遞給shell方法二

    注意sqlplus段使用 col .. new_value .. 定義了變量并帶參數exit, 然后自動賦給了shell的$?

    $ vi test3.sh

    #!/bin/bash
    sqlplus -S /nolog > result.log <<EOF
    set heading off feedback off pagesize 0 verify off echo off numwidth 4
    conn u_test/iamwangnc
    col coun new_value v_coun
    select count(*) coun from tab;
    exit v_coun
    EOF
    VALUE="$?"
    echo "The number of rows is $VALUE."

    $ chmod +x test3.sh
    $ ./test3.sh

    四、把shell程序參數傳遞給sqlplus

    $1表示第一個參數, sqlplus里可以直接使用, 賦變量的等號兩側不能有空格不能有空格.

    $ vi test4.sh

    #!/bin/bash
    NAME="$1"
    sqlplus -S u_test/iamwangnc <<EOF
    select * from tab where tname = upper('$NAME');
    exit
    EOF

    $ chmod +x test4.sh
    $ ./test4.sh ttt

    五、為了安全要求每次執行shell都手工輸入密碼

    $ vi test5.sh

    #!/bin/bash
    echo -n "Enter password for u_test:"
    read PASSWD
    sqlplus -S /nolog <<EOF
    conn u_test/$PASSWD
    select * from tab;
    exit
    EOF

    $ chmod +x test5.sh
    $ ./test5.sh

    六、為了安全從文件讀取密碼

    對密碼文件設置權限, 只有用戶自己才能讀寫.

    $ echo 'iamwangnc' > u_test.txt
    $ chmod g-rwx,o-rwx u_test.txt
    $ vi test6.sh

    #!/bin/bash
    PASSWD=`cat u_test.txt`
    sqlplus -S /nolog <<EOF
    conn u_test/$PASSWD
    select * from tab;
    exit
    EOF

    $ chmod +x test6.sh
    $ ./test6.sh

    --End--
    posted on 2010-04-01 12:05 xzc 閱讀(4799) 評論(0)  編輯  收藏 所屬分類: Oraclelinux/unix
    主站蜘蛛池模板: 亚洲欧洲中文日产| 91精品国产免费久久久久久青草 | 中文字幕日本人妻久久久免费| 99麻豆久久久国产精品免费 | 国产成人AV免费观看| 99ee6热久久免费精品6| 中文字幕av无码无卡免费| 国产精品va无码免费麻豆| 久久99亚洲综合精品首页 | 亚洲免费视频网址| 国产亚洲男人的天堂在线观看| 美女黄网站人色视频免费| 中文字幕无码毛片免费看| 24小时日本韩国高清免费| 国产精品免费一级在线观看| 久久精品夜色噜噜亚洲A∨| 亚洲网站在线播放| 亚洲一卡2卡3卡4卡乱码 在线| 国产精品亚洲色图| 免费国产成人α片| 嫖丰满老熟妇AAAA片免费看| 亚洲AⅤ男人的天堂在线观看| 免费无码H肉动漫在线观看麻豆| 2015日韩永久免费视频播放| 精品免费国产一区二区三区 | 亚洲a级片在线观看| a毛片免费播放全部完整| 我的小后妈韩剧在线看免费高清版 | 国产精成人品日日拍夜夜免费| 国产一区二区免费在线| 亚洲成a人片在线观| 免费观看久久精彩视频| 免费看美女被靠到爽| 亚洲精品成人图区| 国产免费拔擦拔擦8X高清在线人 | 久久国产免费观看精品| 午夜亚洲福利在线老司机| 涩涩色中文综合亚洲| EEUSS影院WWW在线观看免费 | 亚洲第一区二区快射影院| 国产成人 亚洲欧洲|