天天看點

[20170706]ssh diff 問題.txt

[20170706]ssh diff 問題.txt

--//昨天寫的diff 比較執行結果的不同,連結http://blog.itpub.net/267265/viewspace-2141638/

--//如果對比不同機器呢?自然使用ssh. 但是我測試遇到一個問題.

--//通過例子說明

$  ssh [email protected] "lsnrctl status LISTENER_SCAN1"

bash: lsnrctl: command not found

$  ssh [email protected] "date"

Thu Jul  6 09:06:20 CST 2017

$  ssh [email protected] "which lsnrctl"

which: no lsnrctl in (/usr/local/bin:/bin:/usr/bin)

--//很明顯這樣執行ssh環境變量PATH設定是/usr/local/bin:/bin:/usr/bin.

--//檢視man ssh文檔,你可以發現

ENVIRONMENT

     ssh will normally set the following environment variables:

...

     HOME                  Set to the path of the user's home directory.

     LOGNAME               Synonym for USER; set for compatibility with systems that use this variable.

     MAIL                  Set to the path of the user's mailbox.

     PATH                  Set to the default PATH, as specified when compiling ssh.

Additionally, ssh reads ~/.ssh/environment, and adds lines of the format "VARNAME=value" to the environment if the file

exists and users are allowed to change their environment.  For more information, see the PermitUserEnvironment option in

sshd_config(5).

--//根據以上資訊,修改如下:

1.修改服務端的/etc/ssh/sshd_config加入:

PermitUserEnvironment yes

--//注意要重新開機啟動sshd服務才生效!!

2.在服務端的grid使用者建立~/.ssh/environment檔案,内容如下:

$ cat .ssh/environment

TZ=Asia/Shanghai

ORACLE_HOME=/u01/app/11.2.0.4/grid

PATH=/usr/local/bin:/bin:/usr/bin:/u01/app/11.2.0.4/grid/bin

ORACLE_SID=+ASM2

NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'

NLS_TIMESTAMP_FORMAT='YYYY-MM-DD HH24:MI:SS.FF'

NLS_TIMESTAMP_TZ_FORMAT='YYYY-MM-DD HH24:MI:SS.FF'

--//我僅僅把.bash_prifile的内容拷貝過來.

3.測試:

--//在client段執行:

$ ssh [email protected] "lsnrctl status LISTENER_SCAN1"

--//OK,成功!!

$  diff <(lsnrctl status LISTENER_SCAN2) <(ssh [email protected] "lsnrctl status LISTENER_SCAN1")

6c6

< Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER_SCAN2)))

---

> Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER_SCAN1)))

9c9

< Alias                     LISTENER_SCAN2

> Alias                     LISTENER_SCAN1

11,12c11,12

< Start Date                30-JUN-2017 12:00:03

< Uptime                    5 days 21 hr. 21 min. 40 sec

> Start Date                30-JUN-2017 12:01:44

> Uptime                    5 days 21 hr. 19 min. 59 sec

17c17

< Listener Log File         /u01/app/11.2.0.4/grid/network/log/listener_scan2.log

> Listener Log File         /u01/app/11.2.0.4/grid/network/log/listener_scan1.log

19,20c19,20

<   (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER_SCAN2)))

<   (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.xxx.yy9)(PORT=1521)))

>   (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER_SCAN1)))

>   (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.xxx.yy8)(PORT=1521)))

--//這樣就可以現實遠端執行指令的結果進行比較了.當然我僅僅為了測試,不建議這樣使用.

--//還原原來的狀态...

--//實際上如果檔案比較,很簡單例子:

$  diff <(lsnrctl status LISTENER_SCAN2) <(ssh [email protected] "cat /tmp/b1.txt")

--//或者:

$  diff /tmp/b2.txt <(ssh [email protected] "cat /tmp/b1.txt")

$  ssh [email protected] "cat /tmp/b1.txt" | diff /tmp/b2.txt -

--//總結:

--//linux的shell還是很強大的,自己還是精力有限,學習不夠.

繼續閱讀