[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脚本.
--//问题多多,出于安全考虑不建议使用.