<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 閱讀(4792) 評論(0)  編輯  收藏 所屬分類: Oraclelinux/unix
    主站蜘蛛池模板: 亚洲av永久无码精品天堂久久| 成年女人喷潮毛片免费播放| 亚洲国产小视频精品久久久三级| 亚洲中文无码卡通动漫野外| 一个人免费观看www视频在线| 亚洲人成网国产最新在线| 国产成人精品久久免费动漫| 精品亚洲国产成人| 成人免费午夜视频| 亚洲av无码偷拍在线观看| 日本一道高清不卡免费| 亚洲av色香蕉一区二区三区 | 人与动性xxxxx免费| 亚洲国产精品一区二区三区久久 | 国产亚洲人成在线影院| 亚洲人成人网站在线观看| 一区二区免费电影| 无码专区—VA亚洲V天堂| 最近2019免费中文字幕6| 99999久久久久久亚洲| 国产精品国产自线拍免费软件| 国产亚洲福利精品一区二区| 久久精品国产亚洲Aⅴ蜜臀色欲| 日本免费久久久久久久网站| 亚洲成人动漫在线观看| 四虎成人免费网站在线| h视频在线观看免费| 亚洲精品视频免费在线观看| 在线免费观看中文字幕| 中国一级全黄的免费观看| 精品无码一区二区三区亚洲桃色| 成年人免费视频观看| 巨胸狂喷奶水视频www网站免费| 亚洲色图视频在线观看| 国产色婷婷精品免费视频| 永久免费A∨片在线观看| 亚洲私人无码综合久久网| 在线观看亚洲av每日更新| 大学生一级毛片免费看| 一进一出60分钟免费视频| 亚洲成aⅴ人在线观看|