[20170706]ssh diff 问题.txt
--//昨天写的diff 比较执行结果的不同,链接http://blog.itpub.net/267265/viewspace-2141638/
--//如果对比不同机器呢?自然使用ssh. 但是我测试遇到一个问题.
--//通过例子说明
$ ssh grid@192.168.xx.xxx "lsnrctl status LISTENER_SCAN1"
bash: lsnrctl: command not found
$ ssh grid@192.168.aaa.bb6 "date"
Thu Jul 6 09:06:20 CST 2017
$ ssh grid@192.168.aaa.bb6 "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 grid@192.168.aaa.bb6 "lsnrctl status LISTENER_SCAN1"
--//OK,成功!!
$ diff <(lsnrctl status LISTENER_SCAN2) <(ssh grid@192.168.aaa.bb6 "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 grid@192.168.aaa.bb6 "cat /tmp/b1.txt")
--//或者:
$ diff /tmp/b2.txt <(ssh grid@192.168.aaa.bb6 "cat /tmp/b1.txt")
$ ssh grid@192.168.aaa.bb6 "cat /tmp/b1.txt" | diff /tmp/b2.txt -
--//总结:
--//linux的shell还是很强大的,自己还是精力有限,学习不够.