2013-09-27 120 views
-3

我想通過sql查詢到AIX命令的輸出,後面的命令應該用grep的過程,直到條件滿足的過程:grep的使用shell腳本

查詢示例:

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%'); 

OUTPUT :

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 

HERE I GOT SSHD:

SQL> !ps -ef|grep 11075676 
l061749 11075676 20447276 0 11:07:27  - 0:00 sshd: [email protected]/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 

FOR THE 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) 

從本牛瘟的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

+3

我改進了問題的縮進但我不會將ALL CAPS轉換爲普通英文。請相應地編輯您的問題。 – 2013-09-27 05:38:04

+0

我想將sql查詢的輸出傳遞給aix命令,稍後該命令應該grep進程直到滿足條件: – user2822119

回答