[20190110]rlwrap sqlplus tee相關問題3.txt

lfree發表於2019-01-10

[20190110]rlwrap sqlplus tee相關問題3.txt


--//前幾天測試使用rlwrap sqlplus加tee的問題,透過rlwrap的filter功能解決問題,連結:http://blog.itpub.net/267265/viewspace-2375095/

--//不過我發現一些小瑕疵.記錄一下:


1.問題提出:

$ rlwrap -z 'outfilter  tee -a  /tmp/aa.txt'  sqlplus sys as sysdba


SQL*Plus: Release 11.2.0.4.0 Production on Thu Jan 10 08:53:05 2019

Copyright (c) 1982, 2013, Oracle.  All rights reserved.


SQL*Plus: Release 11.2.0.4.0 Production on Thu Jan 10 08:53:05 2019

Copyright (c) 1982, 2013, Oracle.  All rights reserved.


Connected to an idle instance.


SYS@book> startup

ORACLE instance started.


Total System Global Area  643084288 bytes

Fixed Size                  2255872 bytes

Variable Size             205521920 bytes

Database Buffers          427819008 bytes


ORACLE instance started.


Total System Global Area  643084288 bytes

Fixed Size                  2255872 bytes

Variable Size             205521920 bytes

Database Buffers          427819008 bytes



ORACLE instance started.


Total System Global Area  643084288 bytes

Fixed Size                  2255872 bytes

Variable Size             205521920 bytes

Database Buffers          427819008 bytes


Database opened.



Database opened.


--//載入sqlplus時,有時候前面內容會顯示2次,有時候沒有出現.如果提示要口令就一定不會出現.比如執行:

--//rlwrap -z 'outfilter  tee -a  /tmp/aa.txt'  sqlplus / as sysdba

--//或者

--//rlwrap -z 'outfilter  tee -a  /tmp/aa.txt'  sqlplus scott

--//如果啟動資料庫會出現奇特相關資訊顯示3次的情況.


SYS@book> shutdown immediate;

Database closed.


Database closed.


ORACLE instance shut down.


--//關閉資料庫也會出現Database closed.2次.正常關閉如下,比前面重複問題更嚴重的是,關閉資料庫漏掉"Database dismounted."資訊.

SYS@book> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

--//正常啟動資料庫如下:

SYS@book> startup

ORACLE instance started.


Total System Global Area  643084288 bytes

Fixed Size                  2255872 bytes

Variable Size             205521920 bytes

Database Buffers          427819008 bytes

Redo Buffers                7487488 bytes

Database mounted.

Database opened.


--//你可以發現漏掉了

--//Redo Buffers                7487488 bytes,

--//Database mounted.

--//2行資訊.


2.簡單探究:

--//關於輸出重複.

--//檢視rlwrap手冊可以發現如下:


-w, --wait-before-prompt timeout

In order to determine if  command's last output is a prompt, rlwrap waits timeout millisecs after receiving it.  Only

when no more output has arrived, it is cooked (coloured, filtered and/or replaced by a substitute  prompt)  and

displayed  as  a prompt.  Before this the prompt is displayed "uncooked". Most users won't notice, but heavy cookers can

prepend the timeout with a minus sign, making rlwrap hold back the prompt until it has been cooked ("patient mode").

This will prevent flashing of the prompt, but it will also interfere with long output lines and make switches from

direct to readline mode less reliable. Default timeout: 40 ms.


--//你可以測試如果使用過濾,-w 引數要加大才能避免重複輸出.我的測試-w 200基本前面重複的資訊不再出現.


3.簡單探究2:

--//關於輸出遺漏.

--//我不知道這個有什麼好方法,遺漏資訊是因為outfilte指令碼執行如下:

$filter->output_handler(sub {""});

--//而如果沒有這行,輸出資訊會重複.而它就是輸出採用如下:

my $output = $filter->cumulative_output;


--//當執行指令碼時間輸出中間停頓"很長"的情況下,問題很容易再現,透過例子來顯示問題.


$ rlwrap -z 'outfilter   tee -a  /tmp/aa.txt'  -w 200 sqlplus scott/book

SQL*Plus: Release 11.2.0.4.0 Production on Thu Jan 10 15:23:50 2019

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options


--//GRANT EXECUTE ON SYS.DBMS_LOCK TO SCOTT;


CREATE OR REPLACE FUNCTION SCOTT.sleep (seconds IN NUMBER)

   RETURN NUMBER

AS

BEGIN

   sys.DBMS_LOCK.sleep (seconds);

   RETURN seconds;

END;

/


SCOTT@book> create table t as select rownum id,'test' name from dual connect by level<=200;

Table created.


SCOTT@book> set array 4

SCOTT@book> select t.* ,sleep(1) from t where rownum<=10;

        ID NAME                   SLEEP(1)

---------- -------------------- ----------

         1 test                          1

         2 test                          1

         3 test                          1


        ID NAME                   SLEEP(1)

---------- -------------------- ----------

         1 test                          1

         2 test                          1

         3 test                          1


         5 test                          1

         6 test                          1

         7 test                          1


        ID NAME                   SLEEP(1)

---------- -------------------- ----------

         1 test                          1

         2 test                          1

         3 test                          1


         5 test                          1

         6 test                          1

         7 test                          1


         9 test                          1

        10 test                          1

10 rows selected.


--//你可以輸出漏掉了幾行.(id=4,8),並且重複了.放棄,不知道如何改寫outfilter指令碼.

--//問題多多,出於安全考慮不建議使用.


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2375436/,如需轉載,請註明出處,否則將追究法律責任。

相關文章