【发布时间】:2013-09-27 05:35:20
【问题描述】:
我想将 sql 查询的输出传递给 aix 命令,稍后命令应该 grep 进程直到满足条件:
示例查询:
SQL> select vp.spid,vs.process,to_char(logon_time,'DD-MON-YYYY HH24:MI:SS') Logon_Time
2 from v$process vp, v$session vs
3 where
4 vp.addr = vs.paddr and
5 vs.process in
(select Process
6 7 from v$session where username in ('SYS','SYSTEM','OPS$ORACLE')
8 and logon_time >= sysdate-0.010416667
9 and upper(Program) not like 'ORAAGENT%'
10 and upper(Program) not like 'EMAGENT%'
11 and upper(Program) not like 'RMAN%'
and upper(Program) not like 'OMS%'
12 13 and upper(Program) not like 'YRSUPP%');
输出:
SPID PROCESS LOGON_TIME
------------------------ ------------------------ --------------------
18022440 22872252 27-SEP-2013 11:18:01
应该处理 GREP 命令,直到 8 美元的值等于 SSHD:然后切换到 LSOF -I 命令:
SQL> !ps -ef|grep 22872252
oracle 18022440 22872252 0 11:18:01 - 0:00 oracleDSPD21 (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
oracle 20119722 22872252 0 11:41:32 pts/1 0:00 grep 22872252
oracle 22872252 30605374 0 11:18:01 pts/1 0:00 sqlplus
SQL> !ps -ef|grep 30605374
oracle 20643994 22872252 0 11:41:51 pts/1 0:00 grep 30605374
oracle 22872252 30605374 1 11:18:01 pts/1 0:00 sqlplus
oracle 30605374 11993194 0 11:07:31 pts/1 0:00 -ksh
SQL> !ps -ef|grep 11993194
root 11993194 15925354 0 11:07:31 pts/1 0:00 sudo su - oracle
oracle 19791924 22872252 0 11:42:08 pts/1 0:00 grep 11993194
oracle 30605374 11993194 0 11:07:31 pts/1 0:00 -ksh
SQL> !ps -ef|grep 15925354
oracle 10092584 22872252 0 11:42:29 pts/1 0:00 grep 15925354
root 11993194 15925354 0 11:07:31 pts/1 0:00 sudo su - oracle
l061749 15925354 11075676 0 11:07:27 pts/1 0:00 -ksh
在这里我得到了 SSHD:
SQL> !ps -ef|grep 11075676
l061749 11075676 20447276 0 11:07:27 - 0:00 sshd: l061749@pts/1
l061749 15925354 11075676 0 11:07:27 pts/1 0:00 -ksh
oracle 20250734 22872252 0 11:42:57 pts/1 0:00 grep 11075676
对于需要使用以下命令的 SSHD 进程:
SQL> !lsof -i|grep 11075676
lsof: WARNING: can't open /home/oracle/.lsof_ohpr420: Permission denied
sshd 11075676 l061749 3u IPv4 0xf1000e0007dcb3b8 0t50893 TCP ohpr420.rcc.nsw.westpac.com.au:ssh->10.120.119.76:egptlm (ESTABLISHED)
从此 GREP 中获取 IP 地址:
SQL> !lsof -i|grep 20447276
lsof: WARNING: can't open /home/oracle/.lsof_ohpr420: Permission denied
sshd 20447276 root 3u IPv4 0xf1000e0007dcb3b8 0t51813 TCP ohpr420.rcc.nsw.westpac.com.au:ssh->10.120.119.76:egptlm (ESTABLISHED)
请做必要的事情。
感谢和问候 保证
【问题讨论】:
-
我已经改进了您问题的缩进,但我不会将所有大写字母转换为普通英语。请相应地编辑您的问题。
-
我想将sql查询的输出传递给aix命令,稍后命令应该grep进程直到满足条件:
标签: shell