[20170705]diff比較執行結果的內容.txt
–//有時候需要比較2個命令輸出的結果進行比較,比較笨的方法如下,例子:
$? lsnrctl status listener_scan2 > /tmp/b2.txt
$? lsnrctl status listener_scan3 > /tmp/b3.txt
$? diff -nur /tmp/b2.txt /tmp/b3.txt
–//很明顯這樣要生成2個文件,然后比較,實際上利用shell可以很簡單的實現.
$? lsnrctl status listener_scan3 | diff /tmp/2.txt –
–//這樣減少1個文件的生成,可以再減少文件生成嗎?
$? diff
–//如何理解呢?
$? echo? /dev/fd/63 /dev/fd/62
–//實際上62,63就是打開的文件句柄.當然執行完馬上關閉.
$? ls -l /dev/fd
lrwxrwxrwx 1 root root 13 2014-12-11 02:24:57 /dev/fd -> /proc/self/fd
$? ls -l /dev/fd/
total 0
lrwx—— 1 grid oinstall 64 2017-07-05 16:16:07 0 -> /dev/pts/4
lrwx—— 1 grid oinstall 64 2017-07-05 16:16:07 1 -> /dev/pts/4
lrwx—— 1 grid oinstall 64 2017-07-05 16:16:07 2 -> /dev/pts/4
lr-x—— 1 grid oinstall 64 2017-07-05 16:16:07 3 -> /proc/101318/fd
–//寫一個簡單的shell腳本就很好理解了(注意這種寫法不是很嚴謹):
–//我直接讀取句柄63,62的內容.
$? cat a.sh
#! /bin/bash
echo? diff /dev/fd/63 /dev/fd/62
$? . a.sh
/dev/fd/63 /dev/fd/62
6c6
—
> connecting to (description=(address=(protocol=ipc)(key=listener_scan3)))
9c9
—
> alias???????????????????? listener_scan3
11,12c11,12
—
> start date??????????????? 30-jun-2017 12:00:58
> uptime??????????????????? 5 days 4 hr. 17 min. 43 sec
17c17
—
> listener log file???????? /u01/app/11.2.0.4/grid/network/log/listener_scan3.log
19,20c19,20
—
>?? (description=(address=(protocol=ipc)(key=listener_scan3)))
>?? (description=(address=(protocol=tcp)(host=192.168.100.107)(port=1521)))
–//想到這里,我終于理解exp/imp on the fly.例子:
$ exp scott/book file=>(gzip >t.dmp.gz) tables=emp
$ imp scott/book full=y? file=