Shell脚本管道

时间:2017-06-29 14:41:59

标签: shell plsql

#!/bin/sh
output=ANIL;

#
# Ask user for database inputs
#

    echo -n "Enter Database Server Hostname: " 
    read dba_host
    echo -n "Enter Database SID: " 
    read dba_sid
    echo -n "Enter DBA User: " 
    read dba_usr
    echo -n "Enter DBA password: " 
    read dba_pwd
    echo -n "What daemon are we using: "
    read daemon_str

#
#  Loop to connect to database and exit if something is found
#
while :
do

    output=`sqlplus $dba_usr/$dba_pwd@$dba_sid <<+ | grep '^-' | sed 's/-//'
    set serveroutput on
    DECLARE

    command         VARCHAR2(50);
    return_name         VARCHAR2(30);
    value           VARCHAR2(10000);
    status          INT;
    system_time         TIMESTAMP := SYSTIMESTAMP;

    WHILE TRUE
    BEGIN

        status := DBMS_PIPE.RECEIVE_MESSAGE($daemon_str);
        IF status = 0 THEN
            DMS_PIPE.UNPACK_MESSAGE(command);

        END IF;

        IF command = "STOP" THEN
            DBMS_OUTPUT.PUT_LINE('STOP was encountered') >> file.log;
            DBMS_OUTPUT.PUT_LINE(system_time) >> file.log;
            BREAK

        ELSIF command = "SYSTEM" THEN
            DBMS_PIPE.UNPACK_MESSAGE(return_name);
            DBMS_PIPE.UNPACK_MESSAGE(value);
            EXIT
            $value

        ELSIF command = "SQL"
            DBMS_PIPE.UNPACK_MESSAGE(return_name);
            DBMS_PIPE.UNPACK_MESSAGE(value);
            EXECUTE IMMEDIATE value;
        ELSE
            nap(10)
        EXCEPTION
           WHEN OTHERS THEN
            dbms_ouput.put_line('Unknown Input Error') >> file.log;
            DBMS_OUTPUT.PUT_LINE(system_time) >> file.log;

    DBMS_PIPE.PACK_MESSAGE('done');
    DBMS_PIPE.PACK_MESSAGE(status);
    status := DBMS_PIPE.SEND_MESSAGE(return_name,10);

    END;

    dbms_output.put_line(chr(10) || '-' || command);

    END;
    /
    exit

+`
echo $output

done

我正在尝试将c代码块转换为您现在看到的shell脚本块。我只是这种编码语言的初学者,想要知道是否有人看到我不是的东西。总结我想要完成的是询问用户他们想要连接的oracle数据库然后保持连接并通过管道接收内容。然后通常的解包,输出错误等。然后通过相同的管道发回。关于可能的语法或任何可能导致这种情况的任何输入都会导致它不断地回显除while循环中的空行。

0 个答案:

没有答案