使用shell脚本grep该进程

时间:2013-09-27 05:35:21

标签: shell

我想将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)

请做好准备。

感谢和关心 SURESH

1 个答案:

答案 0 :(得分:0)

在AIX上,lsof命令必须由root运行,否则您将收到“Permission denied”消息。

使用lsof命令的好文章。 “谁在使用我的端口?(AIX,Linux,Windows示例)”来自http://www-01.ibm.com/support/docview.wss?uid=swg21264632