: # +----------------------------------------------------------------------------+ # | Jeffrey M. Hunter | # | jhunter@idevelopment.info | # | www.idevelopment.info | # +----------------------------------------------------------------------------| # | Copyright (c) 1998-2012 Jeffrey M. Hunter. All rights reserved. | # +----------------------------------------------------------------------------| # | DATABASE : Oracle | # | FILE : top15 | # | CLASS : UNIX Shell Scripts | # | PURPOSE : Display the top 15 oracle processes. | # | NOTE : As with any code, ensure to test this script in a development | # | environment before attempting to run it in production. | # +----------------------------------------------------------------------------+ # +----------------------------------------------------------------------------+ # | WRITE OUT TEMPORARY FILE | # +----------------------------------------------------------------------------+ echo " SET TERMOUT OFF; COLUMN current_instance NEW_VALUE current_instance NOPRINT; SELECT rpad(instance_name, 17) current_instance FROM v\$instance; SET TERMOUT ON; PROMPT PROMPT +------------------------------------------------------------------------+ PROMPT | Report : Top 15 User Sessions | PROMPT | Instance : ¤t_instance | PROMPT +------------------------------------------------------------------------+ SET LINESIZE 256 SET PAGESIZE 50000 SET TRIMSPOOL ON SET VERIFY OFF COLUMN sid FORMAT 999999 HEADING 'SID' COLUMN serial_id FORMAT 99999999 HEADING 'Serial ID' COLUMN session_status FORMAT a9 HEADING 'Status' COLUMN oracle_username FORMAT a18 HEADING 'Oracle User' COLUMN os_username FORMAT a18 HEADING 'O/S User' COLUMN os_pid FORMAT a8 HEADING 'O/S PID' COLUMN session_terminal FORMAT a10 HEADING 'Terminal' TRUNC COLUMN session_machine FORMAT a30 HEADING 'Machine' TRUNC COLUMN session_program FORMAT a40 HEADING 'Session Program' TRUNC SELECT s.sid sid , s.serial# serial_id , s.status session_status , s.username oracle_username , s.osuser os_username , p.spid os_pid , s.terminal session_terminal , s.machine session_machine , s.program session_program FROM v\$process p , v\$session s WHERE ( p.spid=&1 OR p.spid=&2 OR p.spid=&3 OR p.spid=&4 OR p.spid=&5 OR p.spid=&6 OR p.spid=&7 OR p.spid=&8 OR p.spid=&9 OR p.spid=&10 OR p.spid=&11 OR p.spid=&12 OR p.spid=&13 OR p.spid=&14 OR p.spid=&15 ) AND p.addr (+) = s.paddr AND s.username IS NOT null ORDER BY s.program , s.osuser / EXIT " > top15.sql top -b -n 1 | awk '{if ($2 == "oracle") {print $1;}}' | tail -16 | xargs echo start top15.sql $* > top15_temp.sql sqlplus -s "/ as sysdba" @top15_temp.sql # +----------------------------+ # | REMOVE ALL TEMPORARY FILES | # +----------------------------+ rm top15.sql rm top15_temp.sql