${DB_BASELINE}
export LOGFILE=${DB_BASELINE}
case ${HTMLENABLE} in
y|Y|yes|YES|Yes|ON|On|on)
if [ -x /usr/sbin/sendmail ]
then
export SENDMAIL="/usr/sbin/sendmail -t"
export MAILEXEC="echo #"
export HASHHTML=""
export HASHNONHTML="--"
export HASHHTMLOS=""
export HASHNOHTMLOS="echo #"
SENDMAILARGS=$(
echo "To: ${EMAIL};"
echo "Subject: ${MSGSUBJECT} ;"
echo "Content-Type: text/html;"
echo "MIME-Version: 1.0;"
cat ${LOGFILE}
)
export SENDMAILARGS
else
export SENDMAIL="echo #"
export MAILEXEC="mail -s"
export HASHHTML="--"
export HASHNONHTML=""
export HASHHTMLOS="echo #"
export HASHNOHTMLOS=""
fi
;;
*)
export SENDMAIL="echo #"
export HASHHTML="--"
export HASHNONHTML=""
export HASHHTMLOS="echo #"
export HASHNOHTMLOS=""
export MAILEXEC="mail -s"
;;
esac
# ############################################
# Populating Database Configuration Baseline:
# ############################################
if [ ${INS_COUNT} -gt 0 ]
then
VAL611=$(${ORACLE_HOME}/bin/sqlplus -S "/ as sysdba" << EOF
set linesize 158 pages 300
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD ' ' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
spool ${DB_BASELINE}
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT CONFIGURATION BASELINE FOR DATABASE: ${ORACLE_SID} [Collected on: ${LOGDATE}]
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='3' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT #################################### ########
${HASHNONHTML} PROMPT CONFIGURATION BASELINE FOR DATABASE: ${ORACLE_SID}
${HASHNONHTML} PROMPT #################################### ########
${HASHNONHTML} PROMPT [COLLECTED ON: ${LOGDATE}]
${HASHNONHTML} PROMPT
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT Database General Information:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='3' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT -----------------------------
${HASHNONHTML} PROMPT Database General Information:
${HASHNONHTML} PROMPT -----------------------------
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT INSTANCE INFO:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
PROMPT
${HASHNONHTML} PROMPT INSTANCE INFO:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^
col INST_ID for 9999999
col inst_name for a20
col host_name for a30
col BLOCKED for a7
col STARTUP_TIME for a19
select INST_ID,instance_name INS_NAME,STATUS,DATABASE_STATUS DB_STATUS,VERSION,INSTANCE_ROLE,LOGINS,BLOCKED,to_char(STARTUP_TIME,'DD-MON-YY HH24:MI:SS') STARTUP_TIME from gv\$instance;
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT DATABASE INFO:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT DATABASE INFO:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^
col name for a8
col DB_UNIQUE_NAME for a14
col FLASHBACK for a9
col CURRENT_SCN for 9999999999999999999
col "LOG_MODE | FORCE" for a18
col "PLATFORM_NAME | ID" for a23
col created for a9
col RESETLOGS_TIME for a15
select DBID,NAME, DB_UNIQUE_NAME, DATABASE_ROLE, PROTECTION_MODE, to_char(CREATED,'DD-MON-YY') CREATED, PLATFORM_NAME||' | '||PLATFORM_ID "PLATFORM_NAME | ID", LOG_MODE||' | '||FORCE_LOGGING "LOG_MODE | FORCE", FLASHBACK_ON FLASHBACK,OPEN_MODE, LAST_OPEN_INCARNATION# LAST_INCR#, to_char(RESETLOGS_TIME,'DD-MON-YY HH24:MI') RESETLOGS_TIME,CURRENT_SCN from v\$DATABASE;
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT INSTANCE NON-DEFAULT PARAMETERS:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT INSTANCE NON-DEFAULT PARAMETERS:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
col INST_ID for 9999999
col "PARAMETER_VALUE" for a130
select INST_ID,NAME||'='''||VALUE||'''' "PARAMETER_VALUE"
from gv\$parameter
where ISDEFAULT='FALSE'
order by INST_ID,NAME;
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT DATABASE ENABLED FEATURES:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT DATABASE ENABLED FEATURES:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^^^^^^^^
col PARAMETER for a45
col value for a100
select * from v\$option order by 2,1;
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT DATABASE FEATURES USAGE HISTORY:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT DATABASE FEATURES USAGE HISTORY:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
col name for a65
select NAME,FIRST_USAGE_DATE,LAST_USAGE_DATE,DETECTED_USAGES,AUX_COUNT,ERROR_COUNT from SYS.wri\$_dbu_feature_usage order by 3,2;
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT DATABASE SETTINGS:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT DATABASE SETTINGS:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^
col PROPERTY_NAME for a45
col PROPERTY_VALUE for a100
select PROPERTY_NAME,PROPERTY_VALUE from database_properties order by 1;
col PRODUCT for a60
col VERSION for a20
select PRODUCT,VERSION from product_component_version;
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT BLOCK CHANGE TRACKING:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT BLOCK CHANGE TRACKING:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^^^^
col FILENAME for a80
select * from v\$block_change_tracking;
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT ALL SERVICES: [DBA_SERVICES]
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT ALL SERVICES: [DBA_SERVICES]
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^
col SERVICE_NAME for a30
col NETWORK_NAME for a40
col FAILOVER_METHOD for a15
col FAILOVER_TYPE for a15
col ENABLED for a7
col CLB_GOAL for a8
select NAME SERVICE_NAME, NETWORK_NAME, ENABLED, FAILOVER_METHOD, FAILOVER_TYPE, GOAL, CLB_GOAL, to_char(CREATION_DATE,'DD-MON-YY') CREATED, AQ_HA_NOTIFICATIONS from dba_services order by 1;
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT CLUSTERWARE INTERCONNECT: [GV\$CLUSTER_INTERCONNECTS]
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT CLUSTERWARE INTERCONNECT: [GV\$CLUSTER_INTERCONNECTS]
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^^^^^^^
select * from SYS.GV\$CLUSTER_INTERCONNECTS;
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT PATCHING HISTORY: [DBA_REGISTRY_HISTORY]
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT PATCHING HISTORY: [DBA_REGISTRY_HISTORY]
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^
col ACTION_TIME for a19
col "ACTION | COMMENT" for a80
col VERSION for a12
select to_char(ACTION_TIME,'DD-MON-YY HH24:MI:SS') ACTION_TIME, ACTION||' | '||COMMENTS "ACTION | COMMENT", VERSION from dba_registry_history;
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT DATABASE LINKS:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT DATABASE LINKS:
${HASHNONHTML} PROMPT ---------------
col "OWNER | TARGET_USER" for a45
col DB_LINK for a24
col host for a60
col created format A19 Heading "created"
select OWNER||' | '||USERNAME "OWNER | TARGET_USER",
DB_LINK,
HOST,
to_char(CREATED,'MM/DD/YYYY HH24:MI:SS') created
from dba_db_links
order by OWNER,DB_LINK;
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT DIRECTORIES:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT DIRECTORIES:
${HASHNONHTML} PROMPT ------------
col owner for a30
col DIRECTORY_NAME for a35
col DIRECTORY_PATH for a85
select OWNER,DIRECTORY_NAME,DIRECTORY_PATH from DBA_DIRECTORIES;
PROMPT
${HASHNONHTML} PROMPT ========================================================================================================
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT SECURITY SETTINGS:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='3' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT -------------------
${HASHNONHTML} PROMPT SECURITY SETTINGS:
${HASHNONHTML} PROMPT -------------------
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT ACLS:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT ACLS:
${HASHNONHTML} PROMPT -----
SET lines 160
col host for a35
col ACL for a30
col PRINCIPAL for a15
col ACLID for a35
col start_date for a19
col end_date for a19
col ACL_OWNER for a30
col PRIVILEGE for a20
select * from dba_network_acls;
SELECT * FROM dba_network_acl_privileges;
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT AUDIT SETTINGS:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT AUDIT SETTINGS:
${HASHNONHTML} PROMPT --------------
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT AUDITED SYSTEM PRIVILEGES:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT AUDITED SYSTEM PRIVILEGES:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^^^^^^^^
Select user_name,PRIVILEGE,success,failure from DBA_PRIV_AUDIT_OPTS order by 1,2;
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT AUDITED OBJECT PRIVILEGES:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT AUDITED OBJECT PRIVILEGES:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^^^^^^^^
col "OWNER.OBJECT_NAME" for a30
select OWNER||'.'||OBJECT_NAME "OWNER.OBJECT_NAME",OBJECT_TYPE,ALT,AUD,COM,DEL,GRA,IND,INS,LOC,REN,SEL,UPD,EXE,CRE,REA,WRI,FBK from DBA_OBJ_AUDIT_OPTS order by 1;
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT FINE GRAINED AUDITING SETTINGS:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT FINE GRAINED AUDITING SETTINGS:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Select POLICY_NAME,ENABLED,OBJECT_SCHEMA,OBJECT_NAME,POLICY_COLUMN from DBA_AUDIT_POLICIES;
PROMPT
${HASHNONHTML} PROMPT ========================================================================================================
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT USERS AND PROFILES:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='3' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT --------------------
${HASHNONHTML} PROMPT USERS AND PROFILES:
${HASHNONHTML} PROMPT --------------------
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT USERS:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT USERS:
${HASHNONHTML} PROMPT ^^^^^
set lines 160 pages 300
col USERNAME for a21
col ACCOUNT_STATUS for a20
col EXPIRY_DATE for a11
col LOCK_DATE for a11
col PROFILE for a15
col "CREATE_DATE | PASS_LAST_CHANGE" for a28
col "DEFAULT | TEMPORARY TABLESPACE" for a25
col hash for a16
col LIMIT for a30
select u.USERNAME,u.ACCOUNT_STATUS,u.PROFILE,u.DEFAULT_TABLESPACE||' | '||u.TEMPORARY_TABLESPACE "DEFAULT | TEMPORARY TABLESPACE",to_char(u.EXPIRY_DATE,'DD-MON-YY')EXPIRY_DATE,to_char(u.LOCK_DATE,'DD-MON-YY')LOCK_DATE,s.PASSWORD HASH,
to_char(CTIME,'DD-MON-YY') ||' | '||to_char(s.PTIME,'DD-MON-YY') "CREATE_DATE | PASS_LAST_CHANGE"
from sys.dba_users u, sys.user\$ s where u.username=s.name order by 1;
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT PROFILES:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT PROFILES:
${HASHNONHTML} PROMPT ^^^^^^^^
col PROFILE for a35
select * from dba_profiles order by profile,resource_name;
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT NUMBER OF OBJECTS IN EACH SCHEMA:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT NUMBER OF OBJECTS IN EACH SCHEMA:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
col USERNAME for a25
select USERNAME,
count(decode(o.TYPE#, 2,o.OBJ#,'')) Tables,
count(decode(o.TYPE#, 1,o.OBJ#,'')) Indexes,
count(decode(o.TYPE#, 5,o.OBJ#,'')) Syns,
count(decode(o.TYPE#, 4,o.OBJ#,'')) Views,
count(decode(o.TYPE#, 6,o.OBJ#,'')) Seqs,
count(decode(o.TYPE#, 7,o.OBJ#,'')) Procs,
count(decode(o.TYPE#, 8,o.OBJ#,'')) Funcs,
count(decode(o.TYPE#, 9,o.OBJ#,'')) Pkgs,
count(decode(o.TYPE#,12,o.OBJ#,'')) Trigs,
count(decode(o.TYPE#,10,o.OBJ#,'')) Deps
from SYS.obj\$ o,
SYS.dba_users u
where u.USER_ID = o.OWNER# (+)
group by USERNAME
order by USERNAME;
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT SCHEMAS SIZE:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT SCHEMAS SIZE:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^
set pages 999
col "size MB" format 999,999,999
col "Objects" format 999,999,999
select obj.owner "Owner"
, obj_cnt "Objects"
, decode(seg_size, NULL, 0, seg_size) "size MB"
from (select owner, count(*) obj_cnt from dba_objects group by owner) obj
, (select owner, ceil(sum(bytes)/1024/1024) seg_size
from dba_segments group by owner) seg
where obj.owner = seg.owner(+)
order by 3 desc ,2 desc, 1;
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT BIGGEST 100 OBJECTS:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT BIGGEST 100 OBJECTS:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^^
col owner for a35
col tablespace_name format a35
col segment_name for a35
Select * from (select OWNER,SEGMENT_NAME,SEGMENT_TYPE,TABLESPACE_NAME,BYTES/1024/1024 SIZE_MB from dba_segments order by 5 desc)where rownum <101 order by SIZE_MB desc;
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT Super Users:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='3' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT -------------
${HASHNONHTML} PROMPT Super Users:
${HASHNONHTML} PROMPT -------------
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT SYSDBA USERS:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT SYSDBA USERS:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^
select * from v\$pwfile_users;
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT DBA USERS:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT DBA USERS:
${HASHNONHTML} PROMPT ^^^^^^^^^
select GRANTEE,GRANTED_ROLE from dba_role_privs where granted_role='DBA' order by 1;
--PROMPT
--${HASHNONHTML} PROMPT USERS PERMISSIONS:
--${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^
PROMPT
${HASHNONHTML} PROMPT ========================================================================================================
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT PHYSICAL STRUCTURE:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='3' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT --------------------
${HASHNONHTML} PROMPT PHYSICAL STRUCTURE:
${HASHNONHTML} PROMPT --------------------
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT CONTORLFILES:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT --------------
${HASHNONHTML} PROMPT CONTORLFILES:
${HASHNONHTML} PROMPT --------------
col name for a120
select NAME from V\$CONTROLFILE;
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT REDOLOG GROUPS:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT REDOLOG GROUPS:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^
select THREAD#,GROUP#,MEMBERS,BLOCKSIZE,BYTES/1024/1024"SIZE_MB" from v\$log order by THREAD#,GROUP#;
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT REDOLOG FILES:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT REDOLOG FILES:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^
col MEMBER for a120
select GROUP#,TYPE,MEMBER from v\$logfile order by GROUP#;
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT TABLESPACES:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT ------------
${HASHNONHTML} PROMPT Tablespaces:
${HASHNONHTML} PROMPT ------------
col FORCE_LOGGING for a13
col EXTENT_MANAGEMENT for a12
col ALLOCATION_TYPE for a15
col SEG_SPACE_MANAG for a15
col BIGFILE for a7
col COMPRESSED for a10
col ENCRYPTED for a4
select TABLESPACE_NAME,BLOCK_SIZE,STATUS,CONTENTS,LOGGING,FORCE_LOGGING,EXTENT_MANAGEMENT,ALLOCATION_TYPE,SEGMENT_SPACE_MANAGEMENT SEG_SPACE_MANAG,BIGFILE,DEF_TAB_COMPRESSION COMPRESSED,ENCRYPTED from dba_tablespaces
order by TABLESPACE_NAME;
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT DATAFILES:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT DATAFILES:
${HASHNONHTML} PROMPT ^^^^^^^^^
col FILE_NAME for a90
select TABLESPACE_NAME,FILE_NAME,BYTES/1024/1024 SIZE_MB,MAXBYTES/1024/1024 MAXSIZE_MB,ONLINE_STATUS from dba_data_files order by 1;
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT TABLESPACES UTILIZATION:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT TABLESPACES UTILIZATION:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^^^^^^
col tablespace_name for A25
col Total_MB for 999999999999
col Used_MB for 999999999999
col '%Used' for 999.99
comp sum of Total_MB on report
comp sum of Used_MB on report
comp sum of FREE_MB on report
bre on report
select tablespace_name,
(tablespace_size*$blksize)/(1024*1024) Total_MB,
(used_space*$blksize)/(1024*1024) Used_MB,
used_percent "%Used"
from dba_tablespace_usage_metrics;
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT ASM DISKGROUPS AND DISKFILES:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT ASM DISKGROUPS AND DISKFILES:
${HASHNONHTML} PROMPT ------------------------------
set lines 160
col DISK_FILE_PATH for a40
col DISK_GROUP_NAME for a15
col DISK_FILE_NAME for a15
col DISK_FILE_PATH for a35
col fail_group for a12
col "PCT_USED%" for 999.99
SELECT NVL(a.name, '[CANDIDATE]') disk_group_name
--, b.HEADER_STATUS
, a.type REDUNDANCY
, a.state MOUNT_STAT
--, b.MOUNT_STATUS
, b.STATE
, b.path disk_file_path
, b.name disk_file_name
, b.failgroup fail_group
,b.TOTAL_MB, b.COLD_USED_MB, b.FREE_MB, b.COLD_USED_MB*100/b.TOTAL_MB "PCT_USED%"
FROM v\$asm_diskgroup a RIGHT OUTER JOIN v\$asm_disk b USING (group_number) ORDER BY a.name, b.path;
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT FRA_SIZE:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT FRA_SIZE:
${HASHNONHTML} PROMPT ---------
col name for a25
SELECT NAME,NUMBER_OF_FILES,SPACE_LIMIT/1024/1024/1024 AS TOTAL_SIZE_GB,SPACE_USED/1024/1024/1024 SPACE_USED_GB,
SPACE_RECLAIMABLE/1024/1024/1024 SPACE_RECLAIMABLE_GB,ROUND((SPACE_USED-SPACE_RECLAIMABLE)/SPACE_LIMIT * 100, 1) AS "%FULL_AFTER_CLAIM",
ROUND((SPACE_USED)/SPACE_LIMIT * 100, 1) AS "%FULL_NOW" FROM V\$RECOVERY_FILE_DEST;
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT FRA_COMPONENTS:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT FRA_COMPONENTS:
${HASHNONHTML} PROMPT ---------------
select * from v\$flash_recovery_area_usage;
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT RMAN CONFIGURATIONS:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT ----------------------
${HASHNONHTML} PROMPT RMAN CONFIGURATIONS:
${HASHNONHTML} PROMPT ----------------------
col name for a45
col VALUE for a100
select name, value from v\$rman_configuration;
PROMPT
${HASHNONHTML} PROMPT ========================================================================================================
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT Active Incidents:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT ----------------------
${HASHNONHTML} PROMPT Active Incidents:
${HASHNONHTML} PROMPT ----------------------
set linesize 158
col PROBLEM_KEY for a65
select PROBLEM_KEY,to_char(FIRSTINC_TIME,'DD-MON-YY HH24:mi:ss') FIRST_OCCURENCE,to_char(LASTINC_TIME,'DD-MON-YY HH24:mi:ss')
LAST_OCCURENCE FROM V\$DIAG_PROBLEM;
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT OUTSTANDING ALERTS:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT OUTSTANDING ALERTS:
${HASHNONHTML} PROMPT --------------------------
select * from DBA_OUTSTANDING_ALERTS;
PROMPT
${HASHNONHTML} PROMPT ========================================================================================================
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT SCHEDULED JOBS STATUS:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='3' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT ------------------------------------
${HASHNONHTML} PROMPT SCHEDULED JOBS STATUS:
${HASHNONHTML} PROMPT ------------------------------------
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT DBMS_JOBS:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT DBMS_JOBS:
${HASHNONHTML} PROMPT ----------
set linesize 158
col LAST_RUN for a25
col NEXT_RUN for a25
select job,schema_user,failures,to_char(LAST_DATE,'DD-Mon-YYYY hh24:mi:ss')LAST_RUN,to_char(NEXT_DATE,'DD-Mon-YYYY hh24:mi:ss')NEXT_RUN from dba_jobs;
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT DBMS_SCHEDULER:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT
${HASHNONHTML} PROMPT DBMS_SCHEDULER:
${HASHNONHTML} PROMPT ---------------
col OWNER for a15
col JOB_NAME for a30
col STATE for a10
col FAILURE_COUNT for 9999 heading 'Fail'
col "DURATION(d:hh:mm:ss)" for a22
col REPEAT_INTERVAL for a75
col "LAST_RUN || REPEAT_INTERVAL" for a60
col "DURATION(d:hh:mm:ss)" for a12
--col LAST_START_DATE for a40
select OWNER,JOB_NAME,ENABLED,STATE,FAILURE_COUNT,to_char(LAST_START_DATE,'DD-Mon-YYYY hh24:mi:ss')||' || '||REPEAT_INTERVAL "LAST_RUN || REPEAT_INTERVAL",
extract(day from last_run_duration) ||':'||
lpad(extract(hour from last_run_duration),2,'0')||':'||
lpad(extract(minute from last_run_duration),2,'0')||':'||
lpad(round(extract(second from last_run_duration)),2,'0') "DURATION(d:hh:mm:ss)"
from dba_scheduler_jobs where JOB_NAME NOT LIKE 'AQ$_PLSQL_NTFN%' order by ENABLED,STATE;
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT AUTOTASK INTERNAL MAINTENANCE WINDOWS:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT AUTOTASK INTERNAL MAINTENANCE WINDOWS:
${HASHNONHTML} PROMPT --------------------------------------
col WINDOW_NAME for a17
col NEXT_RUN for a20
col ACTIVE for a6
col OPTIMIZER_STATS for a15
col SEGMENT_ADVISOR for a15
col SQL_TUNE_ADVISOR for a16
col HEALTH_MONITOR for a15
SELECT WINDOW_NAME,TO_CHAR(WINDOW_NEXT_TIME,'DD-MM-YYYY HH24:MI:SS') NEXT_RUN,AUTOTASK_STATUS STATUS,WINDOW_ACTIVE ACTIVE,OPTIMIZER_STATS,SEGMENT_ADVISOR,SQL_TUNE_ADVISOR,HEALTH_MONITOR FROM DBA_AUTOTASK_WINDOW_CLIENTS;
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT FAILED DBMS_SCHEDULER JOBS IN THE LAST 24H:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT FAILED DBMS_SCHEDULER JOBS IN THE LAST 24H:
${HASHNONHTML} PROMPT -------------------------------------------
col LOG_DATE for a36
col OWNER for a15
col JOB_NAME for a35
col STATUS for a11
col RUN_DURATION for a20
col ID for 99
select INSTANCE_ID ID,JOB_NAME,OWNER,LOG_DATE,STATUS,ERROR#,RUN_DURATION from DBA_SCHEDULER_JOB_RUN_DETAILS where LOG_DATE > sysdate-1 and STATUS='FAILED' order by JOB_NAME,LOG_DATE;
PROMPT
${HASHNONHTML} PROMPT ========================================================================================================
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT ADVISORS STATUS:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT ------------------------------
${HASHNONHTML} PROMPT ADVISORS STATUS:
${HASHNONHTML} PROMPT ------------------------------
col CLIENT_NAME for a40
col window_group for a30
col STATUS for a15
col CONSUMER_GROUP for a25
SELECT client_name, status, consumer_group, window_group FROM dba_autotask_client ORDER BY client_name;
PROMPT
${HASHNONHTML} PROMPT ========================================================================================================
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT CURRENT OS / HARDWARE STATISTICS:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT --------------------------------------------------------
${HASHNONHTML} PROMPT CURRENT OS / HARDWARE STATISTICS:
${HASHNONHTML} PROMPT --------------------------------------------------------
col value for 99999999999999999999999
select stat_name,value from v\$osstat;
PROMPT
${HASHNONHTML} PROMPT ========================================================================================================
PROMPT
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT RESOURCE LIMIT:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT --------------------------------
${HASHNONHTML} PROMPT RESOURCE LIMIT:
${HASHNONHTML} PROMPT --------------------------------
col INST_ID for 9999999
col INITIAL_ALLOCATION for a20
col LIMIT_VALUE for a20
select * from gv\$resource_limit order by RESOURCE_NAME;
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT RECYCLEBIN OBJECTS#
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT --------------------------------
${HASHNONHTML} PROMPT RECYCLEBIN OBJECTS#:
${HASHNONHTML} PROMPT --------------------------------
set feedback off
select count(*) "RECYCLED_OBJECTS#",sum(space)*$blksize/1024/1024 "TOTAL_SIZE_MB" from dba_recyclebin group by 1;
set feedback on
${HASHNONHTML} PROMPT
PROMPT [Note: Consider purging DBA_RECYCLEBIN for better performance]
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT FLASHBACK RESTORE POINTS:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT ------------------------------------------
${HASHNONHTML} PROMPT FLASHBACK RESTORE POINTS:
${HASHNONHTML} PROMPT ------------------------------------------
col TIME for a35
col RESTORE_POINT_TIME for a17
col "DATABASE_INCARNATION#" heading "DB_INCR#" for 99999999
col RESTORE_POINT_TIME for a18
select * from V\$RESTORE_POINT;
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT HEALTH MONITOR:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT ----------------------------------
${HASHNONHTML} PROMPT HEALTH MONITOR:
${HASHNONHTML} PROMPT ----------------------------------
select * from V\$HM_RECOMMENDATION where time_detected > sysdate -1;
PROMPT
${HASHNONHTML} PROMPT ========================================================================================================
PROMPT
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT OBJECTS HIGHLIGHTS:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='3' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT -------------------
${HASHNONHTML} PROMPT OBJECTS HIGHLIGHTS:
${HASHNONHTML} PROMPT -------------------
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT INVALID OBJECTS:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT INVALID OBJECTS:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^
col SUBOBJECT_NAME for a30
col status for a15
col "OWNER.OBJECT_NAME" for a55
col LAST_DDL_TIME for a20
select OWNER||'.'||OBJECT_NAME "OWNER.OBJECT_NAME",SUBOBJECT_NAME,OBJECT_TYPE,status,to_char(LAST_DDL_TIME,'DD-MON-YY HH24:mi:ss') LAST_DDL_TIME from DBA_INVALID_OBJECTS;
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT UNUSABLE INDEXES:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT UNUSABLE INDEXES:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^
col INDEX_NAME for a50
col TABLE_NAME for a50
select owner||'.'||INDEX_NAME "INDEX_NAME",INDEX_TYPE,TABLE_OWNER||'.'||TABLE_NAME "TABLE_NAME",COMPRESSION,TABLESPACE_NAME from dba_indexes where status='UNUSABLE';
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT FOREIGN KEY COLUMNS WITHOUT INDEXES:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT FOREIGN KEY COLUMNS WITHOUT INDEXES:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
set linesize 158
col TABLE_NAME for a35
col CONSTRAINT_NAME for a35
col COLUMN_NAME for a22
select acc.OWNER,
acc.TABLE_NAME,
acc.COLUMN_NAME,
acc.CONSTRAINT_NAME,
acc.POSITION,
'No Index' Problem
from dba_cons_columns acc,
dba_constraints ac
where ac.CONSTRAINT_NAME = acc.CONSTRAINT_NAME
and ac.CONSTRAINT_TYPE = 'R'
and acc.OWNER not in ('SYS','SYSTEM','DBSNMP','EXFSYS','MDSYS','ORDDATA','PERFSTAT','STDBYPERF','APEX_050000','SYSMAN','ORDSYS','OLAPSYS')
and not exists (
select 'TRUE'
from dba_ind_columns b
where b.TABLE_OWNER = acc.OWNER
and b.TABLE_NAME = acc.TABLE_NAME
and b.COLUMN_NAME = acc.COLUMN_NAME
and b.COLUMN_POSITION = acc.POSITION)
order by acc.OWNER, acc.CONSTRAINT_NAME, acc.COLUMN_NAME, acc.POSITION;
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT DISABLED CONSTRAINTS:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT DISABLED CONSTRAINTS:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^^^
column OWNER format A20 Heading "OWNER"
column TABLE_NAME format A35 Heading "TABLE_NAME"
column CONSTRAINT_NAME format A35 Heading "CONSTRAINT_NAME"
column STATUS format A12 Heading "STATUS"
column type format A20 Heading "type"
select OWNER,
TABLE_NAME,
CONSTRAINT_NAME,
decode(CONSTRAINT_TYPE, 'C','Check',
'P','Primary Key',
'U','Unique',
'R','Foreign Key',
'V','With Check Option') type,
STATUS
from dba_constraints
where STATUS = 'DISABLED' and OWNER <> 'SYSTEM'
order by OWNER, TABLE_NAME, CONSTRAINT_NAME;
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT Monitored INDEXES:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT Monitored INDEXES:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^
col Index_NAME for a40
col TABLE_NAME for a40
select io.name Index_NAME, t.name TABLE_NAME,decode(bitand(i.flags, 65536),0,'NO','YES') Monitoring,
decode(bitand(ou.flags, 1),0,'NO','YES') USED,ou.start_monitoring,ou.end_monitoring
from sys.obj$ io,sys.obj$ t,sys.ind$ i,sys.object_usage ou where i.obj# = ou.obj# and io.obj# = ou.obj# and t.obj# = i.bo# order by 1;
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT COMPRESSED TABLES:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT COMPRESSED TABLES:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^
SELECT OWNER,TABLE_NAME,TABLESPACE_NAME,COMPRESSION,COMPRESS_FOR FROM DBA_TABLES WHERE COMPRESSION='ENABLED' AND OWNER <> 'SYSMAN' ORDER BY OWNER;
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT PARTITIONED TABLES:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT PARTITIONED TABLES:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^
col table_name format a40
select owner,table_name,DEF_TABLESPACE_NAME,partitioning_type,partition_count
from dba_part_tables
where owner not in ('SYS','SYSTEM','SYSMAN','SQLTXPLAIN')
order by owner;
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT IOT TABLES:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT IOT TABLES:
${HASHNONHTML} PROMPT ^^^^^^^^^^
select owner,table_name,IOT_TYPE from dba_tables where IOT_TYPE='IOT' and owner not in ('SYS','EXFSYS','DBSNMP','WMSYS','CTXSYS','SYSMAN');
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT OBJECTS WITH NON-DEFAULT DEGREE OF PARALLELISM: [Query from: http://blog.tanelpoder.com/?s=index+rebuild]
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT OBJECTS WITH NON-DEFAULT DEGREE OF PARALLELISM: [Query from: http://blog.tanelpoder.com/?s=index+rebuild]
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
col DEGREE for a6
SELECT 'INDEX' OBJECT_TYPE, OWNER, INDEX_NAME, TRIM(DEGREE) DEGREE FROM DBA_INDEXES WHERE TRIM(DEGREE) > TO_CHAR(1)
UNION ALL
SELECT 'TABLE', OWNER, TABLE_NAME, TRIM(DEGREE) DEGREE FROM DBA_TABLES WHERE TRIM(DEGREE) > TO_CHAR(1)
order by 1,2;
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT OBJECTS WITH NOLOGGING OPTION:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT OBJECTS WITH NOLOGGING OPTION:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SELECT 'INDEX' OBJECT_TYPE, OWNER, INDEX_NAME, LOGGING FROM DBA_INDEXES
WHERE LOGGING='NO' AND TEMPORARY='N'
AND owner not in ('SYS','XDB','DBSNMP','SQLTXPLAIN','WMSYS','SYSMAN','SYSTEM','MDSYS','EXFSYS')
UNION ALL
SELECT 'TABLE', OWNER, TABLE_NAME, LOGGING FROM DBA_TABLES
WHERE LOGGING='NO' AND TEMPORARY='N'
AND owner not in ('SYS','XDB','DBSNMP','SQLTXPLAIN','WMSYS','SYSMAN','SYSTEM','MDSYS','EXFSYS')
order by 1,2;
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT CORRUPTED BLOCKS:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT CORRUPTED BLOCKS:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^
select * from V\$DATABASE_BLOCK_CORRUPTION;
PROMPT
${HASHHTML} SET PAGES 1000
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT CONTROLFILE TRACE BACKUP:
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHNONHTML} PROMPT CONTROLFILE TRACE BACKUP:
${HASHNONHTML} PROMPT -------------------------
set feedback off
ALTER DATABASE BACKUP CONTROLFILE TO TRACE AS '${LOG_DIR}/Controlfile_Trc_Bkp_${DB_NAME}.trc' REUSE NORESETLOGS;
spool off
exit;
EOF
)
FILE_NAME=${LOG_DIR}/Controlfile_Trc_Bkp_${DB_NAME}.trc
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${DB_BASELINE}
cat ${FILE_NAME} >> ${DB_BASELINE}
fi
case ${COLLECT_DBUSERS_DDL} in
y|Y|yes|YES|Yes)
export LOGDATE=`date +%d-%b-%y`
SPOOLLOF=${LOG_DIR}/List_Of_Users_${DB_NAME}_${LOGDATE}.log
SPOOL_FILE=${LOG_DIR}/ALL_USERS_DDL_${DB_NAME}_${LOGDATE}.log
cat /dev/null > ${SPOOLLOF}
echo "-------------------" > ${SPOOL_FILE}
echo "-- ALL DB USERS DLL: [Excluding SYSTEM USERS" >> ${SPOOL_FILE}
echo "-------------------" >> ${SPOOL_FILE}
echo "" >> ${SPOOL_FILE}
# Building a list of users --excluding system users to loop on:
VAL_LOOPUSERS=$(${ORACLE_HOME}/bin/sqlplus -s '/ as sysdba' << EOF
PROMPT
spool ${SPOOLLOF}
set pages 0
set echo off heading off feedback off
-- Excluding System users:
select username from dba_users where username not in ('ANONYMOUS','APEX_030200','APEX_PUBLIC_USER','APPQOSSYS','CTXSYS','DBSNMP','EXFSYS','MDDATA','MDSYS','MGMT_VIEW','OLAPSYS','ORACLE_OCM','ORDDATA','ORDPLUGINS','ORDSYS','OUTLN','OWBSYS','OWBSYS_AUDIT','PERFSTAT','SCOTT','SPATIAL_CSW_ADMIN_USR','SPATIAL_WFS_ADMIN_USR','SYS','SYSMAN','SYSTEM','WMSYS','XDB') order by 1;
spool off
EOF
)
# Loop on each user with generating its DDL:
for USERNAME in `cat ${SPOOLLOF}`
do
export USERNAME
VAL_USERSDDL=$(${ORACLE_HOME}/bin/sqlplus -s '/ as sysdba' << EOF
spool ${SPOOL_FILE} APPEND
set termout off
set linesize 150
set pages 50000
set feedback off
set trim on
set echo off
col USERNAME for a30
col account_status for a23
PROMPT
${HASHNONHTML} PROMPT --------------------------------------
${HASHNONHTML} PROMPT -- USER [${USERNAME}]
${HASHNONHTML} PROMPT --------------------------------------
PROMPT
select a.username,a.account_status,a.profile,q.tablespace_name,q.bytes/1024/1024 USED_MB, q.max_bytes "MAX_QUOTA_Bytes" from dba_users a, dba_ts_quotas q where a.username=q.username and a.username='${USERNAME}';
set pages 0
set echo off heading off feedback off
-- Generate Creation Statement:
SELECT 'CREATE USER ' || u.username ||' IDENTIFIED ' ||' BY VALUES ''' || c.password || ''' DEFAULT TABLESPACE ' || u.default_tablespace ||' TEMPORARY TABLESPACE ' || u.temporary_tablespace ||' PROFILE ' || u.profile || case when account_status= 'OPEN' then ';' else ' Account LOCK;' end "--Creation Statement"
FROM dba_users u,user$ c where u.username=c.name and u.username=upper('${USERNAME}')
UNION
-- Generate Granted Roles:
select 'GRANT '||GRANTED_ROLE||' TO '||GRANTEE|| case when ADMIN_OPTION='YES' then ' WITH ADMIN OPTION;' else ';' end "Granted Roles"
from dba_role_privs where grantee= upper('${USERNAME}')
UNION
-- Generate System Privileges:
select 'GRANT '||PRIVILEGE||' TO '||GRANTEE|| case when ADMIN_OPTION='YES' then ' WITH ADMIN OPTION;' else ';' end "Granted System Privileges"
from dba_sys_privs where grantee= upper('${USERNAME}')
UNION
-- Generate Object Privileges:
select 'GRANT '||PRIVILEGE||' ON '||OWNER||'.'||TABLE_NAME||' TO '||GRANTEE||case when GRANTABLE='YES' then ' WITH GRANT OPTION;' else ';' end "Granted Object Privileges"
from DBA_TAB_PRIVS where GRANTEE=upper('${USERNAME}');
spool off
EOF
)
done
echo "" >> ${DB_BASELINE}
echo "-----------------------------" >> ${DB_BASELINE}
echo "-- ALL DB USERS DDL SAVED TO: ${SPOOL_FILE}" >> ${DB_BASELINE}
echo "-----------------------------" >> ${DB_BASELINE}
echo "" >> ${DB_BASELINE}
esac
echo "" >> ${DB_BASELINE}
#echo "" >> ${DB_BASELINE}
#echo "# REPORT BUGS to: mahmmoudadel@hotmail.com" >> ${DB_BASELINE}
#echo "# EVERY MONTH A NEW VERSION OF DBA BUNDLE GET RELEASED, DOWNLOAD IT FROM:" >> ${DB_BASELINE}
#echo "# http://dba-tips.blogspot.com/2014/02/oracle-database-administration-scripts.html" >> ${DB_BASELINE}
case ${MAIL_CONFBASE} in
y|Y|yes|YES|Yes)
sed -i '/^--/d' ${DB_BASELINE}
sed -i '/^rows will be truncated/d' ${DB_BASELINE}
sed -i '/^truncating/d' ${DB_BASELINE}
sed -i '/STARTUP NOMOUNT/d' ${DB_BASELINE}
export LOGFILE=${DB_BASELINE}
export MSGSUBJECT="CONFIGURATION BASELINE | DATABASE [${DB_NAME}] On Server [${SRV_NAME}]"
${MAILEXEC} "${MSGSUBJECT}" ${MAIL_LIST} < ${LOGFILE}
(
echo "To: ${EMAIL};"
echo "MIME-Version: 1.0"
echo "Content-Type: text/html;"
echo "Subject: ${MSGSUBJECT}"
cat ${LOGFILE}
) | ${SENDMAIL}
#mail -s "CONFIGURATION BASELINE | DATABASE [${DB_NAME}] On Server [${SRV_NAME}]" ${MAIL_LIST} < ${DB_BASELINE};;
esac
echo "Configuration Baseline for DATABASE [${DB_NAME}]: ${DB_BASELINE}"
# End looping for databases:
fi
done
# Decide to go forward and collect OS configuration baseline or exit:
case ${DB_CONFBASE_ONLY} in
y|Y|yes|YES|Yes)
# De-Neutralize login.sql file:
# ############################
# If login.sql was renamed during the execution of the script revert it back to its original name:
if [ -f ./login.sql_NeutralizedBy${SCRIPT_NAME} ]
then
mv ./login.sql_NeutralizedBy${SCRIPT_NAME} ./login.sql
fi
if [ -f ${USR_ORA_HOME}/login.sql_NeutralizedBy${SCRIPT_NAME} ]
then
mv ${USR_ORA_HOME}/login.sql_NeutralizedBy${SCRIPT_NAME} ${USR_ORA_HOME}/login.sql
fi
exit;;
esac
# ###############################################################
# OS CONFIGURATION BASELINE
# ###############################################################
echo "# ########################################################" > ${OS_BASELINE}
echo "# OS Configuration Baseline" >> ${OS_BASELINE}
echo "# ########################################################" >> ${OS_BASELINE}
echo "[COLLECTED ON: ${LOGDATE}]" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "============ =============================================" >> ${OS_BASELINE}
echo "SERVER NAME: ${SRV_NAME}" >> ${OS_BASELINE}
echo "============ =============================================" >> ${OS_BASELINE}
FILE_NAME=/etc/oracle-release
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "OS Version:" >> ${OS_BASELINE}
echo "----------" >> ${OS_BASELINE}
cat ${FILE_NAME} >> ${OS_BASELINE}
elif [ -f /etc/redhat-release ]
then
cat /etc/redhat-release >> ${OS_BASELINE}
fi
echo "" >> ${OS_BASELINE}
echo "Uptime Info:" >> ${OS_BASELINE}
echo "-----------" >> ${OS_BASELINE}
uptime >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "Kernel Version:" >> ${OS_BASELINE}
echo "--------------" >> ${OS_BASELINE}
uname -a >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
INST_COUNT=`/bin/ps -ef|grep pmon|grep -v grep |wc -l`
if [ ${INST_COUNT} -gt 0 ]
then
echo "RUNNING DATABASE INSTANCES:" >> ${OS_BASELINE}
echo "--------------------------" >> ${OS_BASELINE}
/bin/ps -ef|grep pmon|grep -v grep >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
fi
LISTENER_COUNT=`/bin/ps -ef|grep tnslsnr|grep -v grep|wc -l`
if [ ${LISTENER_COUNT} -gt 0 ]
then
echo "RUNNING LISTENERS:" >> ${OS_BASELINE}
echo "------------------" >> ${OS_BASELINE}
/bin/ps -ef|grep tnslsnr|grep -v grep >> ${OS_BASELINE}
#for LISTENER_NAME in $( ps -ef|grep -v grep|grep tnslsnr|awk 'NR==1{for (i=1;i<=NF;i++)if ($i=="-inherit"){n=i-1;m=NF-(i==NF)}} {for(i=1;i<=NF;i+=1+(i==n))printf "%s%s",$i,i==m?ORS:OFS}'|awk 'NR==1{for (i=1;i<=NF;i++)if ($i=="-no_crs_notify"){n=i-1;m=NF-(i==NF)}} {for(i=1;i<=NF;i+=1+(i==n))printf "%s%s",$i,i==m?ORS:OFS}'|awk '{print $NF}' )
for LISTENER_NAME in $( ps -ef|grep -v grep|grep tnslsnr|awk '{print $9}' )
do
export LISTENER_NAME
#LISTENER_HOME=`ps -ef|grep -v grep|grep tnslsnr|grep -i ${LISTENER_NAME}|awk 'NR==1{for (i=1;i<=NF;i++)if ($i=="-inherit"){n=i-1;m=NF-(i==NF)}} {for(i=1;i<=NF;i+=1+(i==n))printf "%s%s",$i,i==m?ORS:OFS}'|awk 'NR==1{for (i=1;i<=NF;i++)if ($i=="-no_crs_notify"){n=i-1;m=NF-(i==NF)}} {for(i=1;i<=NF;i+=1+(i==n))printf "%s%s",$i,i==m?ORS:OFS}'|awk '{print $(NF-1)}' |sed -e 's/\/bin\/tnslsnr//g'|grep -v sed|grep -v "s///g"|head -1`
LISTENER_HOME=`ps -ef|grep -v grep|grep tnslsnr|grep -i ${LISTENER_NAME}|awk '{print $8}' |sed -e 's/\/bin\/tnslsnr//g'|grep -v sed|grep -v "s///g"|head -1`
export LISTENER_HOME
TNS_ADMIN=${LISTENER_HOME}/network/admin; export TNS_ADMIN
# For DEBUGGING purpose:
#echo "Listener_name is: $LISTENER_NAME"
#echo "listener_home is: $LISTENER_HOME"
#echo "TNS_ADMIN is: $TNS_ADMIN"
FILE_NAME=${LISTENER_HOME}/bin/lsnrctl
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "LISTENER STATUS: [${LISTENER_NAME}]" >> ${OS_BASELINE}
echo "^^^^^^^^^^^^^^^" >> ${OS_BASELINE}
${LISTENER_HOME}/bin/lsnrctl status ${LISTENER_NAME} >> ${OS_BASELINE}
fi
done
fi
FILE_NAME=/etc/sysconfig/grub
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "Boot Configurations: ${FILE_NAME}" >> ${OS_BASELINE}
echo "-------------------" >> ${OS_BASELINE}
cat ${FILE_NAME} >> ${OS_BASELINE}
fi
# Hashed STARTUP configurations to be run only by root user:
#FILE_NAME=/etc/inittab
#export FILE_NAME
#if [ -f ${FILE_NAME} ]
#then
#echo "" >> ${OS_BASELINE}
#echo "Startup Configurations: ${FILE_NAME}" >> ${OS_BASELINE}
#echo "-------------------------------------" >> ${OS_BASELINE}
#cat ${FILE_NAME} >> ${OS_BASELINE}
#fi
# ############################################
# Checking RAC/ORACLE_RESTART Services:
# ############################################
case ${CLUSTER_CHECK} in
y|Y|yes|YES|Yes)
# Check for ocssd clusterware process:
CHECK_OCSSD=`ps -ef|grep 'ocssd.bin'|grep -v grep|wc -l`
CHECK_CRSD=`ps -ef|grep 'crsd.bin'|grep -v grep|wc -l`
if [ ${CHECK_CRSD} -gt 0 ]
then
CLS_STR=crs
export CLS_STR
CLUSTER_TYPE=CLUSTERWARE
export CLUSTER_TYPE
else
CLS_STR=has
export CLS_STR
CLUSTER_TYPE=ORACLE_RESTART
export CLUSTER_TYPE
fi
if [ ${CHECK_OCSSD} -gt 0 ]
then
GRID_HOME=`ps -ef|grep 'ocssd.bin'|grep -v grep|awk '{print $NF}'|sed -e 's/\/bin\/ocssd.bin//g'|grep -v sed|grep -v "//g"|tail -1`
export GRID_HOME
if [ ! -d ${GRID_HOME} ]
then
ASM_INSTANCE_NAME=`ps -ef|grep pmon|grep -v grep|grep asm_pmon_|awk '{print $NF}'|sed -e 's/asm_pmon_//g'|grep -v sed|grep -v "s///g"|tail -1`
GRID_HOME=`dbhome ${ASM_INSTANCE_NAME}`
export GRID_HOME
fi
GRID_BASE=`cat ${GRID_HOME}/crs/install/crsconfig_params|grep ^ORACLE_BASE|tail -1|awk '{print $NF}'|sed -e 's/ORACLE_BASE=//g'`
export GRID_BASE
if [ ! -d ${GRID_BASE} ]
then
GRID_BASE=`cat ${GRID_HOME}/crs/utl/appvipcfg|grep ^ORACLE_BASE|tail -1|awk '{print $NF}'|sed -e 's/ORACLE_BASE=//g'`
export GRID_BASE
fi
if [ ! -d ${GRID_BASE} ]
then
GRID_BASE=`cat ${GRID_HOME}/install/envVars.properties|grep ^ORACLE_BASE|tail -1|awk '{print $NF}'|sed -e 's/ORACLE_BASE=//g'`
export GRID_BASE
fi
echo "" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "==========================================================" >> ${OS_BASELINE}
echo "${CLUSTER_TYPE} DETAILS" >> ${OS_BASELINE}
echo "==========================================================" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
FILE_NAME=${GRID_HOME}/bin/crsctl
export FILE_NAME
if [ -x ${FILE_NAME} ]
then
echo "CLUSTER VERSION: crsctl query ${CLS_STR} softwareversion" >> ${OS_BASELINE}
echo "---------------" >> ${OS_BASELINE}
${GRID_HOME}/bin/crsctl query ${CLS_STR} softwareversion >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
fi
if [ ${CHECK_CRSD} -gt 0 ]
then
GRID_HOME=`ps -ef|grep 'ocssd.bin'|grep -v grep|awk '{print $NF}'|sed -e 's/\/bin\/ocssd.bin//g'|grep -v sed|grep -v "//g"`
export GRID_HOME
FILE_NAME=${GRID_HOME}/bin/olsnodes
export FILE_NAME
if [ -x ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "CLUSTER NAME: ${FILE_NAME} -c" >> ${OS_BASELINE}
echo "------------" >> ${OS_BASELINE}
${GRID_HOME}/bin/olsnodes -c >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "CLUSTER NODES: ${FILE_NAME} -n -s -t" >> ${OS_BASELINE}
echo "-------------" >> ${OS_BASELINE}
${GRID_HOME}/bin/olsnodes -n -s -t >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
fi
FILE_NAME=${GRID_HOME}/bin/oifcfg
export FILE_NAME
if [ -x ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "CLUSTER INTERCONNECT & PUBLIC IP NAME: oifcfg getif" >> ${OS_BASELINE}
echo "-------------------------------------" >> ${OS_BASELINE}
${GRID_HOME}/bin/oifcfg getif >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
fi
FILE_NAME=${ORACLE_HOME}/bin/srvctl
export FILE_NAME
if [ -x ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "CLUSTER SCAN IPs: srvctl config scan" >> ${OS_BASELINE}
echo "----------------" >> ${OS_BASELINE}
${ORACLE_HOME}/bin/srvctl config scan >> ${OS_BASELINE}
fi
FILE_NAME=${ORACLE_HOME}/bin/srvctl
export FILE_NAME
if [ -x ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "CLUSTER VIRTUAL IP NAME: srvctl config nodeapps" >> ${OS_BASELINE}
echo "-----------------------" >> ${OS_BASELINE}
${ORACLE_HOME}/bin/srvctl config nodeapps >> ${OS_BASELINE}
fi
FILE_NAME=${ORACLE_HOME}/bin/srvctl
export FILE_NAME
if [ -x ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "CLUSTER SCAN Listeners: srvctl config scan_listener" >> ${OS_BASELINE}
echo "----------------------" >> ${OS_BASELINE}
${ORACLE_HOME}/bin/srvctl config scan_listener >> ${OS_BASELINE}
fi
FILE_NAME=${ORACLE_HOME}/bin/srvctl
export FILE_NAME
if [ -x ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "CLUSTER SCAN Listeners status: srvctl status scan_listener" >> ${OS_BASELINE}
echo "-----------------------------" >> ${OS_BASELINE}
${ORACLE_HOME}/bin/srvctl status scan_listener >> ${OS_BASELINE}
fi
FILE_NAME=${GRID_HOME}/bin/ocrcheck
export FILE_NAME
if [ -x ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "^^^^^^^^^^" >> ${OS_BASELINE}
echo "OCR DISKS:" >> ${OS_BASELINE}
echo "^^^^^^^^^^" >> ${OS_BASELINE}
${GRID_HOME}/bin/ocrcheck >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
fi
FILE_NAME=${GRID_HOME}/bin/crsctl
export FILE_NAME
if [ -x ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "^^^^^^^^^^^" >> ${OS_BASELINE}
echo "VOTE DISKS:" >> ${OS_BASELINE}
echo "^^^^^^^^^^^" >> ${OS_BASELINE}
${GRID_HOME}/bin/crsctl query css votedisk >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
fi
fi
FILE_NAME=${ORACLE_HOME}/bin/srvctl
export FILE_NAME
if [ -x ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "ASM CONFIGURATIONS: srvctl config asm" >> ${OS_BASELINE}
echo "------------------" >> ${OS_BASELINE}
${ORACLE_HOME}/bin/srvctl config asm >> ${OS_BASELINE}
fi
FILE_NAME=${GRID_HOME}/bin/crsctl
export FILE_NAME
if [ -x ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "CLUSTERWARE SERVICES: crsctl status resource" >> ${OS_BASELINE}
echo "---------------------" >> ${OS_BASELINE}
AWK=/usr/bin/awk
$AWK \
'BEGIN {printf "%-55s %-24s %-18s\n", "HA Resource", "Target", "State";
printf "%-55s %-24s %-18s\n", "-----------", "------", "-----";}' >> ${OS_BASELINE}
$GRID_HOME/bin/crsctl status resource | $AWK \
'BEGIN { FS="="; state = 0; }
$1~/NAME/ && $2~/'$1'/ {appname = $2; state=1};
state == 0 {next;}
$1~/TARGET/ && state == 1 {apptarget = $2; state=2;}
$1~/STATE/ && state == 2 {appstate = $2; state=3;}
state == 3 {printf "%-55s %-24s %-18s\n", appname, apptarget, appstate; state=0;}' >> ${OS_BASELINE}
fi
# Clustered Databases Configurations:
FILE_NAME=${ORACLE_HOME}/bin/srvctl
export FILE_NAME
if [ -x ${FILE_NAME} ]
then
# Loop for the clustered configured databases:
for CLUSTER_DB in $(${ORACLE_HOME}/bin/srvctl config database)
do
export CLUSTER_DB
echo "" >> ${OS_BASELINE}
echo "^^^^^^^^^^^^^^^^^^^" >> ${OS_BASELINE}
echo "Database [${CLUSTER_DB}]" >> ${OS_BASELINE}
echo "^^^^^^^^^^^^^^^^^^^" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "DATABASE CONFIGURATIONS: srvctl config database -d ${CLUSTER_DB}" >> ${OS_BASELINE}
echo "-----------------------" >> ${OS_BASELINE}
${ORACLE_HOME}/bin/srvctl config database -d ${CLUSTER_DB} >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "DATABASE SERVICES STATUS: srvctl status service -d ${CLUSTER_DB}" >> ${OS_BASELINE}
echo "------------------------" >> ${OS_BASELINE}
${ORACLE_HOME}/bin/srvctl status service -d ${CLUSTER_DB} >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "DATABASE SERVICES CONFIGURATIONS: srvctl config service" >> ${OS_BASELINE}
echo "--------------------------------" >> ${OS_BASELINE}
${ORACLE_HOME}/bin/srvctl config service -d ${CLUSTER_DB} >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
done
fi
FILE_NAME=${GRID_HOME}/crs/install/s_crsconfig_${SRV_NAME}_env.txt
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "CLUSTERWARE NLS_LANG CONFIGURATIONS: ${FILE_NAME}" >> ${OS_BASELINE}
echo "-----------------------------------" >> ${OS_BASELINE}
cat ${FILE_NAME} >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
fi
FILE_NAME=/etc/oracle/ocr.loc
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "OCR DISKS LOCATION: ${FILE_NAME}" >> ${OS_BASELINE}
echo "-------------------" >> ${OS_BASELINE}
cat /etc/oracle/ocr.loc >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
fi
fi
;;
esac
echo "" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "==========================================================" >> ${OS_BASELINE}
echo "ORACLE FILES" >> ${OS_BASELINE}
echo "==========================================================" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
FILE_NAME=${ORATAB}
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "ORATAB: ${FILE_NAME}" >> ${OS_BASELINE}
echo "------" >> ${OS_BASELINE}
cat ${FILE_NAME} >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
fi
# Oracle Network Files:
#TNS_ADMIN=${ORACLE_HOME}/network/admin
#export TNS_ADMIN
FILE_NAME=${TNS_ADMIN}/listener.ora
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "LISTENER: ${FILE_NAME}" >> ${OS_BASELINE}
echo "--------" >> ${OS_BASELINE}
cat ${FILE_NAME} >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
fi
FILE_NAME=${TNS_ADMIN}/tnsnames.ora
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "TNSNAMES: ${FILE_NAME}" >> ${OS_BASELINE}
echo "--------" >> ${OS_BASELINE}
cat ${FILE_NAME} >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
fi
FILE_NAME=${TNS_ADMIN}/sqlnet.ora
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "SQLNET: ${FILE_NAME}" >> ${OS_BASELINE}
echo "------" >> ${OS_BASELINE}
cat ${FILE_NAME} >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
fi
# APPLIED PATCHES DETAILS:
FILE_NAME=${ORACLE_HOME}/OPatch/opatch
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "ORACLE PATCHES DETAILS: opatch lsinventory -details" >> ${OS_BASELINE}
echo "-----------------------" >> ${OS_BASELINE}
${ORACLE_HOME}/OPatch/opatch lsinventory -details >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
fi
# Workaround df command output bug "`/root/.gvfs': Permission denied"
if [ -f /etc/redhat-release ]
then
export DF='df -hTPx fuse.gvfs-fuse-daemon'
else
export DF='df -hT'
fi
echo "" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "==========================================================" >> ${OS_BASELINE}
echo "FILESYSTEM Settings" >> ${OS_BASELINE}
echo "==========================================================" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "df -h" >> ${OS_BASELINE}
echo "------" >> ${OS_BASELINE}
/bin/${DF} >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "mount Command:" >> ${OS_BASELINE}
echo "--------------" >> ${OS_BASELINE}
/bin/mount >> ${OS_BASELINE}
FILE_NAME=/etc/fstab
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "/etc/fstab" >> ${OS_BASELINE}
echo "----------" >> ${OS_BASELINE}
cat ${FILE_NAME} >> ${OS_BASELINE}
fi
FILE_NAME=/sbin/blkid
export FILE_NAME
if [ -x ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "ASM DISKS MOUNT AND LABELS: ${FILE_NAME}" >> ${OS_BASELINE}
echo "--------------------------" >> ${OS_BASELINE}
echo "NOTE: IT'S HIGHLY RECOMMENDED TO RUN THIS COMMAND AS ROOT TO GET AN ACCURATE LIST OF DISKS: /sbin/blkid |sort -k 2 -t:|grep oracleasm" >> ${OS_BASELINE}
# oracleasm listdisks | xargs oracleasm querydisk -p | grep TYPE | sort -k 2
/sbin/blkid |sort -k 2 -t:|grep oracleasm >> ${OS_BASELINE}
fi
FILE_NAME=/etc/exports
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "NFS Shares: ${FILE_NAME}" >> ${OS_BASELINE}
echo "----------" >> ${OS_BASELINE}
cat ${FILE_NAME} >> ${OS_BASELINE}
fi
FILE_NAME=/etc/sysconfig/rawdevices
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "RAW Devices: ${FILE_NAME}" >> ${OS_BASELINE}
echo "------------" >> ${OS_BASELINE}
cat ${FILE_NAME} >> ${OS_BASELINE}
fi
FILE_NAME=/etc/multipath.conf
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "Multipath Configurations: ${FILE_NAME}" >> ${OS_BASELINE}
echo "-------------------------" >> ${OS_BASELINE}
cat ${FILE_NAME} >> ${OS_BASELINE}
fi
FILE_NAME=/etc/sysconfig/oracleasm
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "Oracle ASM Configurations: ${FILE_NAME}" >> ${OS_BASELINE}
echo "--------------------------" >> ${OS_BASELINE}
cat ${FILE_NAME} >> ${OS_BASELINE}
fi
FILE_NAME=/bin/lsblk
export FILE_NAME
if [ -x ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "List of ALL Disks Connected to this Host: lsblk -fo +size" >> ${OS_BASELINE}
echo "----------------------------------------" >> ${OS_BASELINE}
/bin/lsblk -fo +size >> ${OS_BASELINE}
fi
echo "" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "==========================================================" >> ${OS_BASELINE}
echo "USERS AND GROUPS" >> ${OS_BASELINE}
echo "==========================================================" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "Oracle Owner Configuration:" >> ${OS_BASELINE}
echo "---------------------------" >> ${OS_BASELINE}
/usr/bin/id ${ORA_USER} >> ${OS_BASELINE}
/usr/bin/id >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "ACCOUNT Settings:" >> ${OS_BASELINE}
echo "................." >> ${OS_BASELINE}
/usr/bin/chage -l ${ORA_USER} >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "RESOURCE Limits:" >> ${OS_BASELINE}
echo "................" >> ${OS_BASELINE}
ulimit -a >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "CRONTAB Jobs:" >> ${OS_BASELINE}
echo "............." >> ${OS_BASELINE}
/usr/bin/crontab -l 2>/dev/null >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "bash_profile:" >> ${OS_BASELINE}
echo "............." >> ${OS_BASELINE}
cat ~/.bash_profile >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
FILE_NAME=/etc/passwd
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "USERS Configurations: ${FILE_NAME}" >> ${OS_BASELINE}
echo "---------------------" >> ${OS_BASELINE}
cat ${FILE_NAME} >> ${OS_BASELINE}
fi
FILE_NAME=/etc/group
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "GROUPS Configurations: ${FILE_NAME}" >> ${OS_BASELINE}
echo "----------------------" >> ${OS_BASELINE}
cat ${FILE_NAME} >> ${OS_BASELINE}
fi
FILE_NAME=/etc/security/limits.conf
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "USERS LIMITS Configurations: ${FILE_NAME}" >> ${OS_BASELINE}
echo "---------------------------" >> ${OS_BASELINE}
cat ${FILE_NAME} >> ${OS_BASELINE}
fi
FILE_NAME=/etc/profile
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "GENERIC USERS PROFILE: ${FILE_NAME}" >> ${OS_BASELINE}
echo "----------------------" >> ${OS_BASELINE}
cat ${FILE_NAME} >> ${OS_BASELINE}
fi
FILE_NAME=/etc/bashrc
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "GENERIC BASHRC PROFILE: ${FILE_NAME}" >> ${OS_BASELINE}
echo "----------------------" >> ${OS_BASELINE}
cat ${FILE_NAME} >> ${OS_BASELINE}
fi
echo "" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "==========================================================" >> ${OS_BASELINE}
echo "SECURITY Settings" >> ${OS_BASELINE}
echo "==========================================================" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
FILE_NAME=/etc/pam.d/system-auth
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "PAM Configurations: ${FILE_NAME}" >> ${OS_BASELINE}
echo "-------------------" >> ${OS_BASELINE}
cat ${FILE_NAME} >> ${OS_BASELINE}
fi
FILE_NAME=/etc/login.defs
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "LOGINS DEFAULT Configurations: ${FILE_NAME}" >> ${OS_BASELINE}
echo "------------------------------" >> ${OS_BASELINE}
cat ${FILE_NAME} >> ${OS_BASELINE}
fi
# Hashed FIREWALL configurations to be run only by root user:
#FILE_NAME=/etc/sysconfig/iptables-config
#export FILE_NAME
#if [ -f ${FILE_NAME} ]
#then
#echo "" >> ${OS_BASELINE}
#echo "FIREWALL Configurations: ${FILE_NAME}" >> ${OS_BASELINE}
#echo "-----------------------" >> ${OS_BASELINE}
#cat ${FILE_NAME} >> ${OS_BASELINE}
#fi
#FILE_NAME=/etc/sysconfig/iptables
#export FILE_NAME
#if [ -f ${FILE_NAME} ]
#then
#echo "" >> ${OS_BASELINE}
#echo "FIREWALL RULES: ${FILE_NAME}" >> ${OS_BASELINE}
#echo "--------------" >> ${OS_BASELINE}
#cat ${FILE_NAME} >> ${OS_BASELINE}
#fi
FILE_NAME=/etc/sysconfig/selinux
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "SELINUX Configurations: ${FILE_NAME}" >> ${OS_BASELINE}
echo "-----------------------" >> ${OS_BASELINE}
cat ${FILE_NAME} >> ${OS_BASELINE}
fi
FILE_NAME=/etc/issue
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "INTRO Message Configuration: ${FILE_NAME}" >> ${OS_BASELINE}
echo "----------------------------" >> ${OS_BASELINE}
cat ${FILE_NAME} >> ${OS_BASELINE}
fi
echo "" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "==========================================================" >> ${OS_BASELINE}
echo "SERVICES Configurations" >> ${OS_BASELINE}
echo "==========================================================" >> ${OS_BASELINE}
#FILE_NAME=/sbin/service
#export FILE_NAME
#if [ -f ${FILE_NAME} ]
#then
#echo "" >> ${OS_BASELINE}
#echo "RUNNING SERVICES: /sbin/service --status-all" >> ${OS_BASELINE}
#echo "-----------------" >> ${OS_BASELINE}
#/sbin/service --status-all 2>/dev/null >> ${OS_BASELINE}
#echo "" >> ${OS_BASELINE}
#fi
FILE_NAME=/sbin/chkconfig
export FILE_NAME
if [ -x ${FILE_NAME} ]
then
if [ -f /etc/rc.d/init.d ]
then
echo "" >> ${OS_BASELINE}
echo "SERVICES Settings: chkconfig --list" >> ${OS_BASELINE}
echo "-----------------" >> ${OS_BASELINE}
/sbin/chkconfig --list|sort >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
fi
fi
echo "" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "==========================================================" >> ${OS_BASELINE}
echo "NETWORK Settings" >> ${OS_BASELINE}
echo "==========================================================" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
FILE_NAME=/etc/sysconfig/network
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "GENERAL NETWORK Configurations: ${FILE_NAME}" >> ${OS_BASELINE}
echo "------------------------------" >> ${OS_BASELINE}
cat ${FILE_NAME} >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
fi
FILE_NAME=/etc/resolv.conf
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "DNS Configurations: ${FILE_NAME}" >> ${OS_BASELINE}
echo "------------------" >> ${OS_BASELINE}
cat ${FILE_NAME} >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
fi
FILE_NAME=/sbin/ifconfig
export FILE_NAME
if [ -x ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "NICs Configurations: [ifconfig -a]" >> ${OS_BASELINE}
echo "--------------------" >> ${OS_BASELINE}
/sbin/ifconfig -a >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
fi
echo "" >> ${OS_BASELINE}
echo "Routing Table: [netstat -rn]" >> ${OS_BASELINE}
echo "--------------" >> ${OS_BASELINE}
netstat -rn >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "NICs Config Files:" >> ${OS_BASELINE}
echo "------------------" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
for FILE_NAME in /etc/sysconfig/network-scripts/ifcfg-*
do
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "cat ${FILE_NAME}" >> ${OS_BASELINE}
echo "............................................." >> ${OS_BASELINE}
cat ${FILE_NAME} >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
fi
done
echo "" >> ${OS_BASELINE}
FILE_NAME=/etc/modprobe.conf
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "NICs/BONDING ALIASES: ${FILE_NAME}" >> ${OS_BASELINE}
echo "--------------------" >> ${OS_BASELINE}
cat ${FILE_NAME} >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
fi
FILE_NAME=/etc/hosts
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "${FILE_NAME} Configurations:" >> ${OS_BASELINE}
echo "---------------------------" >> ${OS_BASELINE}
cat ${FILE_NAME} >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
fi
FILE_NAME=/etc/hosts.allow
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "TCP WRAPPER: ALLOWED HOSTS: ${FILE_NAME}" >> ${OS_BASELINE}
echo "---------------------------" >> ${OS_BASELINE}
cat ${FILE_NAME} >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
fi
FILE_NAME=/etc/hosts.deny
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "TCP WRAPPER: DENIED HOSTS: ${FILE_NAME}" >> ${OS_BASELINE}
echo "--------------------------" >> ${OS_BASELINE}
cat ${FILE_NAME} >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
fi
FILE_NAME=/etc/mail/sendmail.mc
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "SMTP SERVER: ${FILE_NAME}" >> ${OS_BASELINE}
echo "-----------" >> ${OS_BASELINE}
cat /etc/mail/sendmail.mc|grep SMART >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
fi
# https://superuser.com/questions/529830/get-a-list-of-open-ports-in-linux [datashaman]
FILE_NAME=/bin/netstat
export FILE_NAME
if [ -x ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "Open Ports:" >> ${OS_BASELINE}
echo "^^^^^^^^^^^" >> ${OS_BASELINE}
netstat -lnt | awk 'NR>2{print $4}' | grep -E '(0.0.0.0:|:::)' | sed 's/.*://' | sort -n | uniq >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
fi
echo "" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "==========================================================" >> ${OS_BASELINE}
echo "TIME AND DATE Configurations" >> ${OS_BASELINE}
echo "==========================================================" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
FILE_NAME=/etc/localtime
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "LOCAL TIME Configurations: ${FILE_NAME}" >> ${OS_BASELINE}
echo "-------------------------" >> ${OS_BASELINE}
tail -1 ${FILE_NAME} >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
fi
FILE_NAME=/sbin/chkconfig
export FILE_NAME
if [ -x ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "NTP SERVICE STATUS: chkconfig --list|grep ntp" >> ${OS_BASELINE}
echo "------------------" >> ${OS_BASELINE}
/sbin/chkconfig --list|grep ntp >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
fi
FILE_NAME=/etc/ntp.conf
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "NTP Configurations: ${FILE_NAME}" >> ${OS_BASELINE}
echo "------------------" >> ${OS_BASELINE}
cat ${FILE_NAME} >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
fi
FILE_NAME=/etc/sysconfig/ntpd
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "NTP Settings: ${FILE_NAME}" >> ${OS_BASELINE}
echo "------------" >> ${OS_BASELINE}
cat ${FILE_NAME} >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
fi
echo "" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "==========================================================" >> ${OS_BASELINE}
echo "LOGGING Settings" >> ${OS_BASELINE}
echo "==========================================================" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
FILE_NAME=/etc/sysconfig/syslog
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "SYSLOG Settings: ${FILE_NAME}" >> ${OS_BASELINE}
echo "---------------" >> ${OS_BASELINE}
cat ${FILE_NAME} >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
fi
FILE_NAME=/etc/sysconfig/sysstat
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "KEEP LOG Settings: ${FILE_NAME}" >> ${OS_BASELINE}
echo "-----------------" >> ${OS_BASELINE}
cat ${FILE_NAME} >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
fi
FILE_NAME=/etc/logrotate.conf
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "ROTATE LOG Settings: ${FILE_NAME}" >> ${OS_BASELINE}
echo "-------------------" >> ${OS_BASELINE}
cat ${FILE_NAME} >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
fi
echo "" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "==========================================================" >> ${OS_BASELINE}
echo "CURRENT RESOURCES INFORMATION" >> ${OS_BASELINE}
echo "==========================================================" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
FILE_NAME=/dev/mem
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "ALL HARDWARE DETAILS: dmidecode" >> ${OS_BASELINE}
echo "---------------------" >> ${OS_BASELINE}
/usr/sbin/dmidecode >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
fi
FILE_NAME=/sbin/lspci
export FILE_NAME
if [ -x ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "PCI DEVICES DETAILS: lspci" >> ${OS_BASELINE}
echo "-------------------" >> ${OS_BASELINE}
/sbin/lspci >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
fi
FILE_NAME=/proc/cpuinfo
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "CPU DETAILS: ${FILE_NAME}" >> ${OS_BASELINE}
echo "-----------" >> ${OS_BASELINE}
cat ${FILE_NAME} >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
fi
FILE_NAME=/proc/meminfo
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "MEMORY DETAILS: ${FILE_NAME}" >> ${OS_BASELINE}
echo "--------------" >> ${OS_BASELINE}
cat ${FILE_NAME} >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
fi
echo "" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "==========================================================" >> ${OS_BASELINE}
echo "KERNEL Settings" >> ${OS_BASELINE}
echo "==========================================================" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
FILE_NAME=/etc/sysctl.conf
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "Kernel NON-DEFAULT PARAMETERS: ${FILE_NAME}" >> ${OS_BASELINE}
echo "-----------------------------" >> ${OS_BASELINE}
cat ${FILE_NAME} >> ${OS_BASELINE}
fi
FILE_NAME=/sbin/sysctl
export FILE_NAME
if [ -x ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "ALL KERNEL PARAMETERS:" >> ${OS_BASELINE}
echo "----------------------" >> ${OS_BASELINE}
/sbin/sysctl -a 2>/dev/null >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
fi
FILE_NAME=/bin/rpm
export FILE_NAME
if [ -x ${FILE_NAME} ]
then
echo "" >> ${OS_BASELINE}
echo "List Of ALL INSTALLED PACKAGES:" >> ${OS_BASELINE}
echo "------------------------------" >> ${OS_BASELINE}
/bin/rpm -qa|sort >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
fi
echo "" >> ${OS_BASELINE}
echo "---------------------------------" >> ${OS_BASELINE}
echo "END OF OS CONFIGURATION BASELINE." >> ${OS_BASELINE}
echo "---------------------------------" >> ${OS_BASELINE}
echo "" >> ${OS_BASELINE}
echo "# REPORT BUGS to: mahmmoudadel@hotmail.com" >> ${OS_BASELINE}
echo "# DOWNLOAD THE LATEST VERSION OF DBA BUNDLE FROM:" >> ${OS_BASELINE}
echo "# http://dba-tips.blogspot.com/2014/02/oracle-database-administration-scripts.html" >> ${OS_BASELINE}
case ${MAIL_CONFBASE} in
y|Y|yes|YES|Yes)
mail -s "CONFIGURATION BASELINE | SERVER [${SRV_NAME}]" ${MAIL_LIST} < ${OS_BASELINE};;
esac
echo "Configuration Baseline for OPERATING SYSTEM: ${OS_BASELINE}"
echo ""
# De-Neutralize login.sql file:
# ############################
# If login.sql was renamed during the execution of the script revert it back to its original name:
if [ -f ./login.sql_NeutralizedBy${SCRIPT_NAME} ]
then
mv ./login.sql_NeutralizedBy${SCRIPT_NAME} ./login.sql
fi
if [ -f ${USR_ORA_HOME}/login.sql_NeutralizedBy${SCRIPT_NAME} ]
then
mv ${USR_ORA_HOME}/login.sql_NeutralizedBy${SCRIPT_NAME} ${USR_ORA_HOME}/login.sql
fi
# #############
# END OF SCRIPT
# #############
# REPORT BUGS to: mahmmoudadel@hotmail.com
# DOWNLOAD THE LATEST VERSION OF DATABASE ADMINISTRATION BUNDLE FROM:
# http://dba-tips.blogspot.com/2014/02/oracle-database-administration-scripts.html
# DISCLAIMER: THIS SCRIPT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY WARRANTY. IT IS PROVIDED "AS IS".
DBA_BUNDLE6/login.sql.bundle 0000640 0152073 0152061 00000014064 14122405700 015543 0 ustar oracle oinstall -- --------------------------------------------------------------------------------
-- Ver 2.3
-- This script improves the display of SQLPlus environment
--
-- Author: Mahmmoud ADEL
-- Updates: 14-09-21 Enabled Parallelism on session level if used by the DBA.
-- 14-09-21 Enabled DDL LOCK Timeout to avoid getting resource
-- busy error when altering busy table.
-- --------------------------------------------------------------------------------
PROMPT <>
PROMPT
set sqlprompt "_date' '_user'@'_connect_identifier> "
set linesize 170
set pages 1000
set long 32000
col name for a60
col OWNER for a25
col SCHEMANAME for a25
col OBJECT_NAME for a40
col PASSWORD for a30
col OSPID for a10
col PROGRAM for a40
col MODULE for a40
col MACHINE for a40
col ACTION for a25
col EVENT for a25
col WAIT_CLASS for a25
col TRACEID for a25
col TRACEFILE for a65
col inst_name for a20
col host_name for a30
col host for a45
col member for a70
col file_name for a70
col OS_USERNAME for a20
col OSUSER for a20
col username for a20
col user_name for a20
col userhost for a20
col DB_LINK for a30
col TERMINAL for a15
col P1TEXT for a15
col P2TEXT for a15
col P3TEXT for a15
col ID for 99
col TIMESTAMP for a30
col ACTION_NAME for a10
col OPNAME for a21
col limit for a30
col LAST_LOGIN for a30
col profile for a35
col COMMENTS for a60
col DESCRIPTION for a60
col resource for a30
col ACTION_TIME for a30
col MESSAGE for a77
col SERVICE_NAME for a15
col EXTERNAL_NAME for a15
col resource_name for a30
col DEFAULT_COLLATION for a20
col ACCOUNT_STATUS for a16
col tablespace_name for a40
col DIRECTORY_NAME for a30
col DIRECTORY_PATH for a60
col PROPERTY_NAME for a27
col PROPERTY_VALUE for a30
col CURRENT_SCN for 99999999999999999
col INITIAL_RSRC_CONSUMER_GROUP for a20
-- Used by Trusted Oracle
COLUMN ROWLABEL FORMAT A15
-- Used for the SHOW ERRORS command
COLUMN LINE/COL FORMAT A8
COLUMN ERROR FORMAT A65 WORD_WRAPPED
-- Used for the SHOW SGA command
COLUMN name_col_plus_show_sga FORMAT a24
-- Defaults for SHOW PARAMETERS
COLUMN name_col_plus_show_param FORMAT a36 HEADING NAME
COLUMN value_col_plus_show_param FORMAT a99 HEADING VALUE
-- Defaults for SET AUTOTRACE EXPLAIN report
COLUMN id_plus_exp FORMAT 990 HEADING i
COLUMN parent_id_plus_exp FORMAT 990 HEADING p
COLUMN plan_plus_exp FORMAT a60
COLUMN object_node_plus_exp FORMAT a8
COLUMN other_tag_plus_exp FORMAT a29
COLUMN other_plus_exp FORMAT a44
set pages 0 feedback off lines 25
-- Setting DATE format:
alter session set nls_date_format = 'DD-Mon-YYYY HH24:MI:SS';
-- Setting Session identifier:
EXEC DBMS_SESSION.set_identifier('LOCAL_SESSION_POWERDED_BY_DBA_BUNDLE');
-- Setting DDL LOCK Timeout: [30 seconds]
alter session set ddl_lock_timeout=30;
-- Enable Parallelism on Session level:
alter session enable parallel dml;
alter session enable parallel ddl;
alter session enable parallel query;
col INS_NAME for a11
col INST_ID heading ID for 99
col STATUS for a9
col DB_OPEN_MODE for a12
col "DB_STATUS|OPEN_MODE" for a27
col "LOG_MODE|FORCE" for a15
col FLASHBACK for a9
col BLOCKED for a7
col STARTUP_TIME for a18
PROMPT My Session Details:
PROMPT -------------------
select /*+RULE*/ 'SID | '||s.sid, 'Serial# | '||s.serial#, 'OSPID | '||p.spid
from v$session s, v$process p
where s.sid = (select sid from v$mystat where rownum = 1) and s.paddr=p.addr;
set pages 100 lines 170
select /*+RULE*/ s.inst_id ID,s.instance_name INS_NAME,d.NAME DB_NAME,s.STATUS INS_STATUS,s.DATABASE_STATUS||'|'||d.OPEN_MODE "DB_STATUS|OPEN_MODE",d.DATABASE_ROLE DB_ROLE,d.LOG_MODE||'|'||d.FORCE_LOGGING "LOG_MODE|FORCE",d.FLASHBACK_ON FLASHBACK,s.LOGINS,to_char(s.STARTUP_TIME,'DD-MON-YY HH24:MI:SS') STARTUP_TIME
from gv$instance s, v$database d order by 1;
/*
set serveroutput on
declare
ins_bundle varchar2(10);
insstatus_bundle varchar2(20);
dbstatus_bundle varchar2(20);
logins_bundle varchar2(20);
blocked_bundle varchar2(20);
startupt_bundle varchar2(40);
db_bundle varchar2(20);
logmode_bundle varchar2(20);
forcelog_bundle varchar2(20);
flashback_bundle varchar2(20);
openmode_bundle varchar2(30);
dbrole_bundle varchar2(20);
sid_bundle number;
serial_bundle number;
spid_bundle number;
begin
select s.sid, s.serial#, p.spid into sid_bundle, serial_bundle, spid_bundle from v$session s, v$process p
where s.sid = (select sid from v$mystat where rownum = 1) and s.paddr=p.addr;
select instance_name,STATUS,DATABASE_STATUS,LOGINS,BLOCKED,to_char(STARTUP_TIME,'DD-MON-YY HH24:MI:SS')
into ins_bundle,insstatus_bundle,dbstatus_bundle,logins_bundle,blocked_bundle,startupt_bundle from gv$instance;
select name,LOG_MODE,FORCE_LOGGING,flashback_on,OPEN_MODE,DATABASE_ROLE
into db_bundle,logmode_bundle,forcelog_bundle,flashback_bundle,openmode_bundle,dbrole_bundle from v$database;
dbms_output.put_line('------------------ ------------------');
dbms_output.put_line('INS Name|Status: ' || ins_bundle || ' | ' || insstatus_bundle);
dbms_output.put_line('DB Name|Status: ' || db_bundle || ' | ' || dbstatus_bundle);
dbms_output.put_line('DB Mode: ' || openmode_bundle);
dbms_output.put_line('DB Role: ' || dbrole_bundle);
dbms_output.put_line('Logins: ' || logins_bundle);
dbms_output.put_line('Services Blocked: ' || blocked_bundle);
dbms_output.put_line('ARCHIVELOG Mode: ' || logmode_bundle);
dbms_output.put_line('FORCE LOGGING: ' || forcelog_bundle);
dbms_output.put_line('FLASHBACK Mode: ' || flashback_bundle);
dbms_output.put_line('Startup Time: ' || startupt_bundle);
dbms_output.put_line('------------------ ------------------');
dbms_output.put_line('My SID: ' || sid_bundle);
dbms_output.put_line('My Serial#: ' || serial_bundle);
dbms_output.put_line('My OSPID: ' || spid_bundle);
dbms_output.put_line('------------------ ------------------');
end;
/
*/
set pages 1000 feedback on
prompt
DBA_BUNDLE6/dbdailychk.sh 0000740 0152073 0152061 00000317271 14122402715 015106 0 ustar oracle oinstall # ##################################################################################################################################
# DATABASE DAILY HEALTH CHECK MONITORING SCRIPT
VER="[6.2]"
# ===================================================================================================
# CAUTION: THIS SCRIPT MAY CAUSE A SLIGHT OVEARHEAD, DO NOT RUN IT TOO FREQUENT, ONCE A DAY IS IDEAL.
# ===================================================================================================
# ***********
# How To Use:
# ***********
# 1- Set your Email by modifying this parameter below: EMAIL="youremail@yourcompany.com"
# 2- Check the THRESHOLDS section and make sure they meet your policy.
# 3- You can DISABLE/ENABLE some section by altering the parameter that accept Y or N values
# e.g. Disable Memory Check Section in the report:
# Go to THRESHOLDS section and set:
# CHECK_MEMORY=N
# ****************************************************************************************************
# FEATURES:
# ********
# CHECKING CPU UTILIZATION.
# CHECKING FILESYSTEM UTILIZATION.
# CHECKING TABLESPACES UTILIZATION.
# CHECKING FLASH RECOVERY AREA UTILIZATION.
# CHECKING ASM DISKGROUPS UTILIZATION.
# CHECKING BLOCKING SESSIONS ON THE DATABASE.
# CHECKING UNUSABLE INDEXES ON THE DATABASE.
# CHECKING INVALID OBJECTS ON THE DATABASE.
# CHECKING CORRUPTED BLOCKS ON THE DATABASE.
# CHECKING FAILED JOBS IN THE DATABASE.
# CHECKING LONG RUNNING JOBS [For More than 1 Day].
# CHECKING ACTIVE INCIDENTS.
# CHECKING OUTSTANDING ALERTS.
# CHECKING DATABASE SIZE GROWTH.
# CHECKING RMAN BACKUPs.
# REPORT UNRECOVERABLE DB FILES.
# CHECKING OS / HARDWARE STATISTICS.
# CHECKING RESOURCE LIMITS.
# CHECKING RECYCLEBIN.
# CHECKING CURRENT RESTORE POINTS.
# CHECKING HEALTH MONITOR CHECKS RECOMMENDATIONS THAT RUN BY DBMS_HM PACKAGE.
# CHEKCING MONITORED INDEXES.
# CHECKING REDOLOG SWITCHES.
# CHECKING MODIFIED INTIALIZATION PARAMETERS SINCE THE LAST DB STARTUP.
# CHECKING ADVISORS RECOMMENDATIONS:
# - SQL TUNING ADVISOR
# - SGA ADVISOR
# - PGA ADVISOR
# - BUFFER CACHE ADVISOR
# - SHARED POOL ADVISOR
# - SEGMENT ADVISOR
# CHECKING NEW CREATED OBJECTS.
# CHECKING AUDIT RECORDS.
# CHECKING FAILED LOGIN ATTEMPTS.
#
# # # #
# Author: Mahmmoud ADEL # # # # ###
# # # # # #
#
# Created: 22-12-13 Based on dbalarm.sh script.
# Modifications:18-05-14 Added Filsystem monitoring.
# 19-05-14 Added CPU monitoring.
# 09-12-14 Added Tablespaces monitoring
# Added BLOCKING SESSIONS monitoring
# Added UNUSABLE INDEXES monitoring
# Added INVALID OBJECTS monitoring
# Added FAILED LOGINS monitoring
# Added AUDIT RECORDS monitoring
# Added CORRUPTED BLOCKS monitoring
# [It will NOT run a SCAN. It will look at V$DATABASE_BLOCK_CORRUPTION]
# Added FAILED JOBS monitoring.
# 06-10-15 Replaced mpstat with iostat for CPU Utilization Check
# 02-11-15 Enhanced "FAILED JOBS monitoring" part.
# 13-12-15 Added Advisors Recommendations to the report
# 04-04-16 dba_tablespace_usage_metrics view will be used for 11g onwards versions
# for checking tablespaces size, advised by: Satyajit Mohapatra
# 10-04-16 Add Flash Recovery Area monitoring
# 10-04-16 Add ASM Disk Groups monitoring
# 15-07-16 Add ACTIVE INCIDENTS, RESOURCE LIMITS, RECYCLEBIN, RESTORE POINTS,
# MONITORED INDEXES, REDOLOG SWITCHES, MODIFIED SPFILE PARAMETERS checks.
# 02-01-17 Removed ALERTLOG check for DB & Listener +
# Merged alerts with advisors. [Recommended by: ABD-ELGAWAD]
# 03-01-17 Added checking RAC status feature. [Recommended by: Samer ALJazzar]
# 09-01-17 Added RMAN BACKUP CHECK.
# 04-05-17 Added Reporting of Newly Created Objects in the last 24Hours.
# 12-06-17 Added Long Running Jobs Alert.
# 20-07-17 Neutralize login.sql if found under Oracle user home directory due to bugs.
# 10-10-17 Added reporting Long Running Queries to the report.
# 09-01-18 Workaround for df command bug "`/root/.gvfs': Permission denied"
# 16-05-18 Added SHOWSQLTUNINGADVISOR, SHOWMEMORYADVISORS, SHOWSEGMENTADVVISOR, SHOWJOBS
# and SHOWHASHEDCRED parameters to allow the user to decide whether to show their
# results in the report or not.
# 21-06-18 Added MODOBJCONTTHRESHOLD to control the display of LAST MODIFIED OBJECTS in the report.
# 15-08-18 Added REPORT UNRECOVERABLE DATABASE FILES that don't have a valid backup.
# 10-02-19 Removed the failed jobs alerting from the script.
# 19-02-19 Added HTML email format content.
# 04-04-19 Added Reporting of Top Fragmented Tables.
# 16-06-20 Excluding goldengate modules from Long Running Queries reporting.
# 22-06-20 Modified the check for cluster services to get compatible with 12c+.
# 23-06-20 Listed: Running Instances/listeners, open ports in the report.
# 14-09-20 Added Memory utilization check feature, combining both RAM and SWAP in the calculation.
# 14-09-20 Reorganize script sections to make it easy to edit by users.
# 23-11-20 Enhance df command output in HTML mode
# 04-04-21 Listing Dormant accounts in the report.
# 04-04-21 Auditing data will be included in the report by default. [If AUD$ is big this section will take much time]
# 20-09-21 Show yesterday's hardware (CPU & Memory) stats if crossed the thresholds.
#
#
#
# ##################################################################################################################################
# HERE YOU SET YOUR EMAIL:
EMAIL="youremail@yourcompany.com"
# HERE YOU SET THE SMTP SERVER IF EXIST. UNHASH THE BELOW LINE AND REPLACE "mailrelay.mycompany.com" WITH YOUR COMPANY's SMTP:
#export smtp="mailrelay.mycompany.com:25" # This is an example, your Network Admin knows the SMTP NAME & PORT to use.
# #########################
# THRESHOLDS:
# #########################
# Send an E-mail for each THRESHOLD if been reached:
# ADJUST the following THRESHOLD VALUES as per your requirements:
HTMLENABLE=Y # Enable HTML Email Format [DB]
FSTHRESHOLD=95 # THRESHOLD FOR FILESYSTEM %USED [OS]
CPUTHRESHOLD=95 # THRESHOLD FOR CPU %UTILIZATION [OS]
CHECK_MEMORY=Y # REPORT LOW MEMORY USING BELOW TWO DEFINED THRESHOLDS COMBINED [OS]
USEDPHYSICALMEM_PCT=95 # THRESHOLD FOR RAM %UTILIZATION [OS]
USEDSWAPMEM_PCT=75 # THRESHOLD FOR SWAP SPACE %UTILIZATION [OS]
CHECK_CLUSTER=Y # CHECK CLUSTERWARE HEALTH [CL]
CHKAUDITRECORDS=Y # INCLUDE AUDIT RECORDS IN THE REPORT [increases CPU Load] [DB]
SHOWDORMANTACCOUNTS=Y # SHOW INACTIVE ACCOUNTS IN THE REPORT [DB]
DORMANT_INACTIVE_DAYS=45 # SHOW Inactive Accounts with NO login attempts since 45 days.[DB]
SHOWSQLTUNINGADVISOR=Y # INCLUDE SQL TUNING ADVISOR RESULTS IN THE REPORT [DB]
SHOWMEMORYADVISORS=Y # INCLUDE MEMORY ADVISORS RESULTS IN THE REPORT [DB]
SHOWSEGMENTADVVISOR=N # INCLUDE SEGMENT ADVISOR RESULTS IN THE REPORT [DB]
SHOWJOBS=Y # INCLUDE DB JOBS DETAILS IN THE REPORT [DB]
SHOWHASHEDCRED=N # INCLUDE DB USERS HASHED VERSION CREDENTIALS IN THE REPORT [DB]
REPORTUNRECOVERABLE=Y # INCLUDE UNRECOVERABLE DATAFILES IN THE REPORT. [DB]
TBSTHRESHOLD=95 # THRESHOLD FOR TABLESPACE %USED [DB]
FRATHRESHOLD=95 # THRESHOLD FOR FLASH RECOVERY AREA %USED [DB]
ASMTHRESHOLD=95 # THRESHOLD FOR ASM DISK GROUPS [DB]
UNUSEINDXTHRESHOLD=1 # THRESHOLD FOR NUMBER OF UNUSABLE INDEXES [DB]
INVOBJECTTHRESHOLD=1 # THRESHOLD FOR NUMBER OF INVALID OBJECTS [DB]
FAILLOGINTHRESHOLD=1 # THRESHOLD FOR NUMBER OF FAILED LOGINS [DB]
AUDITRECOTHRESHOLD=1 # THRESHOLD FOR NUMBER OF AUDIT RECORDS [DB]
CORUPTBLKTHRESHOLD=1 # THRESHOLD FOR NUMBER OF CORRUPTED BLOCKS [DB]
FAILDJOBSTHRESHOLD=1 # THRESHOLD FOR NUMBER OF FAILED JOBS [DB]
JOBSRUNSINCENDAY=1 # THRESHOLD FOR JOBS RUNNING LONGER THAN N DAY [DB]
NEWOBJCONTTHRESHOLD=1 # THRESHOLD FOR NUMBER OF NEWLY CREATED OBJECTS [DB]
MODOBJCONTTHRESHOLD=1 # THRESHOLD FOR NUMBER OF MODIFIED OBJECTS [DB]
LONG_RUN_QUR_HOURS=1 # THRESHOLD FOR QUERIES RUNNING LONGER THAN N HOURS [DB]
SHOW_YESTERDAY_STATS=Y # CHECKER FOR SHOWING HARDWARE RESOURCES THAT CROSSED THRESHOLDS[OS]
# #######################################
# Excluded Modules:
# #######################################
# Here you can exclude the modules you don't want their queries to get reported in the Long Running Queries list:
# goldegate modules are excluded below, to add extra modules, make sure to enclose them between single quote and separating them by a comma:
EXCLUDED_MODULES="'OGG-USE_OCI_THREAD','OGG-OCI_META_THREAD'"
# #######################################
# Excluded INSTANCES:
# #######################################
# Here you can mention the instances the script will IGNORE and will NOT run against:
# Use pipe "|" as a separator between each instance name.
# e.g. Excluding: -MGMTDB, ASM instances:
EXL_DB="\-MGMTDB|ASM|APX" #Excluding INSTANCES [Will get excluded from the report].
# #########################
# Excluded ERRORS:
# #########################
# Here you can exclude the errors that you don't want to be alerted when they appear in the logs:
# Use pipe "|" between each error.
EXL_ALERT_ERR="ORA-2396|TNS-00507|TNS-12502|TNS-12560|TNS-12537|TNS-00505" #Excluded ALERTLOG ERRORS [Will not get reported].
EXL_LSNR_ERR="TNS-00507|TNS-12502|TNS-12560|TNS-12537|TNS-00505" #Excluded LISTENER ERRORS [Will not get reported].
# ################################
# Excluded FILESYSTEM/MOUNT POINTS:
# ################################
# Here you can exclude specific filesystems/mount points from being reported by the script:
# e.g. Excluding: /dev/mapper, /dev/asm mount points:
EXL_FS="\/dev\/mapper\/|\/dev\/asm\/" #Excluded mount points [Will be skipped during the check].
# Workaround df command output bug "`/root/.gvfs': Permission denied"
if [ -f /etc/redhat-release ]
then
export DF='df -hTPx fuse.gvfs-fuse-daemon'
else
export DF='df -hT'
fi
export SRV_NAME="`uname -n`"
case ${EMAIL} in "youremail@yourcompany.com")
echo
echo "##############################################################################################"
echo "You Missed Something! :-)"
echo "In order to receive the HEALTH CHECK report via Email, set your E-mail at line# 110"
echo "by replacing this template [youremail@yourcompany.com] with YOUR E-mail address."
echo "DB HEALTH CHECK report will be saved on disk..."
echo "##############################################################################################"
export SQLLINESIZE=165
echo;;
*)
export SQLLINESIZE=200
export OSLINESIZE=300
;;
esac
SCRIPT_NAME="dbdailychk${VER}"
# In case your company Emails go through a specific SMTP server. Specify it in the below line and UN-HASH it:
#export smtp="mailrelay.mycompany.com:25" #This is an example, you have to check with your Network Admin for the SMTP NAME/PORT to use.
export MAIL_LIST="${EMAIL}"
#export MAIL_LIST="-r ${SRV_NAME} ${EMAIL}"
echo
echo "[dbdailychk Script Started ...]"
# #########################
# Checking The FILESYSTEM:
# #########################
# Report Partitions that reach the threshold of Used Space:
FSLOG=/tmp/filesystem_DBA_BUNDLE.log
echo "[Reported By ${SCRIPT_NAME} Script" > ${FSLOG}
echo "" >> ${FSLOG}
${DF} >> ${FSLOG}
${DF} | grep -v "^Filesystem" |awk '{print substr($0, index($0, $2))}'| egrep -v "${EXL_FS}"|awk '{print $(NF-1)" "$NF}'| while read OUTPUT
do
PRCUSED=`echo ${OUTPUT}|awk '{print $1}'|cut -d'%' -f1`
FILESYS=`echo ${OUTPUT}|awk '{print $2}'`
if [ ${PRCUSED} -ge ${FSTHRESHOLD} ]
then
mail -s "ALARM: Filesystem [${FILESYS}] on Server [${SRV_NAME}] has reached ${PRCUSED}% of USED space" ${MAIL_LIST} < ${FSLOG}
fi
done
rm -f ${FSLOG}
# #########################
# Getting ORACLE_SID:
# #########################
# Exit with sending Alert mail if No DBs are running:
INS_COUNT=$( ps -ef|grep pmon|grep -v grep|egrep -v ${EXL_DB}|wc -l )
if [ $INS_COUNT -eq 0 ]
then
echo "[Reported By ${SCRIPT_NAME} Script]" > /tmp/oracle_processes_DBA_BUNDLE.log
echo " " >> /tmp/oracle_processes_DBA_BUNDLE.log
echo "Current running INSTANCES on server [${SRV_NAME}]:" >> /tmp/oracle_processes_DBA_BUNDLE.log
echo "***************************************************" >> /tmp/oracle_processes_DBA_BUNDLE.log
ps -ef|grep -v grep|grep pmon >> /tmp/oracle_processes_DBA_BUNDLE.log
echo " " >> /tmp/oracle_processes_DBA_BUNDLE.log
echo "Current running LISTENERS on server [${SRV_NAME}]:" >> /tmp/oracle_processes_DBA_BUNDLE.log
echo "***************************************************" >> /tmp/oracle_processes_DBA_BUNDLE.log
ps -ef|grep -v grep|grep tnslsnr >> /tmp/oracle_processes_DBA_BUNDLE.log
mail -s "ALARM: No Databases Are Running on Server ${SRV_NAME} !!!" ${MAIL_LIST} < /tmp/oracle_processes_DBA_BUNDLE.log
rm -f /tmp/oracle_processes_DBA_BUNDLE.log
exit
fi
# #########################
# Setting ORACLE_SID:
# #########################
for ORACLE_SID in $( ps -ef|grep pmon|grep -v grep|egrep -v ${EXL_DB}|awk '{print $NF}'|sed -e 's/ora_pmon_//g'|grep -v sed|grep -v "s///g" )
do
export ORACLE_SID
# #########################
# Getting ORACLE_HOME
# #########################
ORA_USER=`ps -ef|grep ${ORACLE_SID}|grep pmon|grep -v grep|egrep -v ${EXL_DB}|grep -v "\-MGMTDB"|awk '{print $1}'|tail -1`
USR_ORA_HOME=`grep -i "^${ORA_USER}:" /etc/passwd| cut -f6 -d ':'|tail -1`
# SETTING ORATAB:
if [ -f /etc/oratab ]
then
ORATAB=/etc/oratab
export ORATAB
## If OS is Solaris:
elif [ -f /var/opt/oracle/oratab ]
then
ORATAB=/var/opt/oracle/oratab
export ORATAB
fi
# ATTEMPT1: Get ORACLE_HOME using pwdx command:
export PGREP=`which pgrep`
export PWDX=`which pwdx`
if [[ -x ${PGREP} ]] && [[ -x ${PWDX} ]]
then
PMON_PID=`pgrep -lf _pmon_${ORACLE_SID}|awk '{print $1}'`
export PMON_PID
ORACLE_HOME=`pwdx ${PMON_PID}|awk '{print $NF}'|sed -e 's/\/dbs//g'`
export ORACLE_HOME
fi
# ATTEMPT2: If ORACLE_HOME not found get it from oratab file:
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
## If OS is Linux:
if [ -f /etc/oratab ]
then
ORATAB=/etc/oratab
ORACLE_HOME=`grep -v '^\#' ${ORATAB} | grep -v '^$'| grep -i "^${ORACLE_SID}:" | perl -lpe'$_ = reverse' | cut -f3 | perl -lpe'$_ = reverse' |cut -f2 -d':'`
export ORACLE_HOME
## If OS is Solaris:
elif [ -f /var/opt/oracle/oratab ]
then
ORATAB=/var/opt/oracle/oratab
ORACLE_HOME=`grep -v '^\#' ${ORATAB} | grep -v '^$'| grep -i "^${ORACLE_SID}:" | perl -lpe'$_ = reverse' | cut -f3 | perl -lpe'$_ = reverse' |cut -f2 -d':'`
export ORACLE_HOME
fi
fi
# ATTEMPT3: If ORACLE_HOME is in /etc/oratab, use dbhome command:
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
ORACLE_HOME=`dbhome "${ORACLE_SID}"`
export ORACLE_HOME
fi
# ATTEMPT4: If ORACLE_HOME is still not found, search for the environment variable: [Less accurate]
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
ORACLE_HOME=`env|grep -i ORACLE_HOME|sed -e 's/ORACLE_HOME=//g'`
export ORACLE_HOME
fi
# ATTEMPT5: If ORACLE_HOME is not found in the environment search user's profile: [Less accurate]
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
ORACLE_HOME=`grep -h 'ORACLE_HOME=\/' ${USR_ORA_HOME}/.bash_profile ${USR_ORA_HOME}/.*profile | perl -lpe'$_ = reverse' |cut -f1 -d'=' | perl -lpe'$_ = reverse'|tail -1`
export ORACLE_HOME
fi
# ATTEMPT6: If ORACLE_HOME is still not found, search for orapipe: [Least accurate]
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
if [ -x /usr/bin/locate ]
then
ORACLE_HOME=`locate -i orapipe|head -1|sed -e 's/\/bin\/orapipe//g'`
export ORACLE_HOME
fi
fi
# TERMINATE: If all above attempts failed to get ORACLE_HOME location, EXIT the script:
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
echo "Please export ORACLE_HOME variable in your .bash_profile file under oracle user home directory in order to get this script to run properly"
echo "e.g."
echo "export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1"
mail -s "dbdailychk script on Server [${SRV_NAME}] failed to locate ORACLE_HOME for SID [${ORACLE_SID}], Please export ORACLE_HOME variable in your .bash_profile file under oracle user home directory" ${MAIL_LIST} < /dev/null
exit
fi
export LD_LIBRARY_PATH=${ORACLE_HOME}/lib
# #############################
# Getting hostname in lowercase:
# #############################
HOSTNAMELOWER=$( echo "`hostname --short`"| tr '[A-Z]' '[a-z]' )
export HOSTNAMELOWER
# ########################
# Getting GRID_HOME:
# ########################
CHECK_OCSSD=`ps -ef|grep 'ocssd.bin'|grep -v grep|wc -l`
CHECK_CRSD=`ps -ef|grep 'crsd.bin'|grep -v grep|wc -l`
if [ ${CHECK_OCSSD} -gt 0 ]
then
GRID_HOME=`ps -ef|grep 'ocssd.bin'|grep -v grep|awk '{print $NF}'|sed -e 's/\/bin\/ocssd.bin//g'|grep -v sed|grep -v "//g"|tail -1`
export GRID_HOME
if [ ! -d ${GRID_HOME} ]
then
ASM_INSTANCE_NAME=`ps -ef|grep pmon|grep -v grep|grep asm_pmon_|awk '{print $NF}'|sed -e 's/asm_pmon_//g'|grep -v sed|grep -v "s///g"|tail -1`
GRID_HOME=`dbhome ${ASM_INSTANCE_NAME}`
export GRID_HOME
fi
# ########################
# Getting GRID_BASE:
# ########################
# Locating GRID_BASE:
GRID_BASE=`cat ${GRID_HOME}/crs/install/crsconfig_params|grep ^ORACLE_BASE|tail -1|awk '{print $NF}'|sed -e 's/ORACLE_BASE=//g'`
export GRID_BASE
if [ ! -d ${GRID_BASE} ]
then
GRID_BASE=`cat ${GRID_HOME}/crs/utl/appvipcfg|grep ^ORACLE_BASE|tail -1|awk '{print $NF}'|sed -e 's/ORACLE_BASE=//g'`
export GRID_BASE
fi
if [ ! -d ${GRID_BASE} ]
then
GRID_BASE=`cat ${GRID_HOME}/install/envVars.properties|grep ^ORACLE_BASE|tail -1|awk '{print $NF}'|sed -e 's/ORACLE_BASE=//g'`
export GRID_BASE
fi
fi
# #########################
# Variables:
# #########################
export PATH=${PATH}:${ORACLE_HOME}/bin
export LOG_DIR=${USR_ORA_HOME}/BUNDLE_Logs
mkdir -p ${LOG_DIR}
chown -R ${ORA_USER} ${LOG_DIR}
chmod -R go-rwx ${LOG_DIR}
if [ ! -d ${LOG_DIR} ]
then
mkdir -p /tmp/BUNDLE_Logs
export LOG_DIR=/tmp/BUNDLE_Logs
chown -R ${ORA_USER} ${LOG_DIR}
chmod -R go-rwx ${LOG_DIR}
fi
cat /dev/null > ${LOG_DIR}/dbdailychk.part.log
export LOGFILE=${LOG_DIR}/dbdailychk.part.log
# #########################
# HTML Preparation:
# #########################
case ${HTMLENABLE} in
y|Y|yes|YES|Yes|ON|On|on)
if [ -x /usr/sbin/sendmail ]
then
export SENDMAIL="/usr/sbin/sendmail -t"
export MAILEXEC="echo #"
export HASHHTML=""
export HASHNONHTML="--"
export HASHHTMLOS=""
export HASHNOHTMLOS="echo #"
SENDMAILARGS=$(
echo "To: ${EMAIL};"
echo "Subject: ${MSGSUBJECT} ;"
echo "Content-Type: text/html;"
echo "MIME-Version: 1.0;"
cat ${LOGFILE}
)
export SENDMAILARGS
else
export SENDMAIL="echo #"
export MAILEXEC="mail -s"
export HASHHTML="--"
export HASHNONHTML=""
export HASHHTMLOS="echo #"
export HASHNOHTMLOS=""
fi
;;
*)
export SENDMAIL="echo #"
export HASHHTML="--"
export HASHNONHTML=""
export HASHHTMLOS="echo #"
export HASHNOHTMLOS=""
export MAILEXEC="mail -s"
;;
esac
export LOGFILE=${LOG_DIR}/dbdailychk.part.log
export SRV_NAME="`uname -n`"
# ##########################
# Neutralize login.sql file: [Bug Fix]
# ##########################
# Existance of login.sql file under Oracle user Linux home directory eliminates many functions during the execution of this script from crontab:
if [ -f ${USR_ORA_HOME}/login.sql ]
then
#echo "login.sql file found and will be neutralized."
mv ${USR_ORA_HOME}/login.sql ${USR_ORA_HOME}/login.sql_NeutralizedBy${SCRIPT_NAME}
fi
# ########################
# Getting ORACLE_BASE:
# ########################
# Get ORACLE_BASE from user's profile if it EMPTY:
if [ ! -d "${ORACLE_BASE}" ]
then
ORACLE_BASE=`cat ${ORACLE_HOME}/install/envVars.properties|grep ^ORACLE_BASE|tail -1|awk '{print $NF}'|sed -e 's/ORACLE_BASE=//g'`
export ORACLE_BASE
fi
if [ ! -d "${ORACLE_BASE}" ]
then
ORACLE_BASE=`grep -h 'ORACLE_BASE=\/' ${USR_ORA_HOME}/.bash* ${USR_ORA_HOME}/.*profile | perl -lpe'$_ = reverse' |cut -f1 -d'=' | perl -lpe'$_ = reverse'|tail -1`
export ORACLE_BASE
fi
# #########################
# Getting DB_NAME:
# #########################
DB_NAME_RAW=$(${ORACLE_HOME}/bin/sqlplus -S "/ as sysdba" < ${JOBSRUNSINCENDAY} and SESSION_ID is not null;
SELECT count(*) from dba_scheduler_running_jobs where extract(day FROM elapsed_time) > ${JOBSRUNSINCENDAY};
exit;
EOF
)
VAL510=`echo ${VAL410} | awk '{print $NF}'`
if [ ${VAL510} -ge 1 ]
then
VAL610=$(${ORACLE_HOME}/bin/sqlplus -S "/ as sysdba" << EOF
set linesize ${SQLLINESIZE} pages 1000
-- Enable HTML color format:
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD ' ' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
spool ${LOGFILE}
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT Long Running Jobs [${ORACLE_SID}]
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} PROMPT Long Running Jobs: [${ORACLE_SID}]
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^
col INS for 999
col "JOB_NAME|OWNER|SPID|SID" for a55
col ELAPSED_TIME for a17
col CPU_USED for a17
col "WAIT_SEC" for 9999999999
col WAIT_CLASS for a15
col "BLKD_BY" for 9999999
col "WAITED|WCLASS|EVENT" for a45
select j.RUNNING_INSTANCE INS,j.JOB_NAME ||' | '|| j.OWNER||' |'||SLAVE_OS_PROCESS_ID||'|'||j.SESSION_ID"JOB_NAME|OWNER|SPID|SID"
,s.FINAL_BLOCKING_SESSION "BLKD_BY",ELAPSED_TIME,CPU_USED
,substr(s.SECONDS_IN_WAIT||'|'||s.WAIT_CLASS||'|'||s.EVENT,1,45) "WAITED|WCLASS|EVENT",S.SQL_ID
from dba_scheduler_running_jobs j, gv\$session s
where j.RUNNING_INSTANCE=S.INST_ID(+)
and j.SESSION_ID=S.SID(+)
and extract(day FROM elapsed_time) > ${JOBSRUNSINCENDAY}
order by "JOB_NAME|OWNER|SPID|SID",ELAPSED_TIME;
spool off
exit;
EOF
)
#mail -s "WARNING: JOBS running for more than ${JOBSRUNSINCENDAY} day detected on database [${DB_NAME_UPPER}] on Server [${SRV_NAME}]" ${MAIL_LIST} < ${LOG_DIR}/long_running_jobs.log
export MSGSUBJECT="WARNING: JOBS running for more than ${JOBSRUNSINCENDAY} day detected on database [${DB_NAME_UPPER}] on Server [${SRV_NAME}]"
#SENDMAILARGS=$(
#echo "To: ${EMAIL};"
#echo "Subject: ${MSGSUBJECT} ;"
#echo "Content-Type: text/html;"
#echo "MIME-Version: 1.0;"
#cat ${LOGFILE}
#)
${MAILEXEC} "${MSGSUBJECT}" ${MAIL_LIST} < ${LOGFILE}
#echo ${SENDMAILARGS} | tr \; '\n' |awk 'length == 1 || NR == 1 {print $0} length && NR > 1 { print substr($0,2) }'| ${SENDMAIL}
(
echo "To: ${EMAIL};"
echo "MIME-Version: 1.0"
echo "Content-Type: text/html;"
echo "Subject: ${MSGSUBJECT}"
cat ${LOGFILE}
) | ${SENDMAIL}
cat /dev/null > ${LOGFILE}
fi
# ############################################
# LOGFILE SETTINGS:
# ############################################
# Logfile path variable:
DB_HEALTHCHK_RPT=${LOG_DIR}/${DB_NAME_UPPER}_HEALTH_CHECK_REPORT.log
OS_HEALTHCHK_RPT=${LOG_DIR}/OS_HEALTH_CHECK_REPORT.log
export DB_HEALTHCHK_RPT
# Flush the logfile:
export LOGDATE=`date +%d-%b-%y`
echo "HEALTH_CHECK_REPORT_FOR_DATABASE_[${DB_NAME_UPPER}]_ON_{${LOGDATE}}" > ${DB_HEALTHCHK_RPT}
cat /dev/null > ${OS_HEALTHCHK_RPT}
# ###########################
# Checking Memory Utilization:
# ###########################
case ${CHECK_MEMORY} in
y|Y|yes|YES|Yes|ON|On|on)
# Check the Linux OS version:
export PATH=${PATH}:/usr/local/bin
FILE_NAME=/etc/redhat-release
export FILE_NAME
if [ -f ${FILE_NAME} ]
then
LNXVER=`cat /etc/redhat-release | grep -o '[0-9]'|head -1`
export LNXVER
# IF LINUX VERSION IS 6 OR LOWER:
if [ ${LNXVER} -le 6 ]
then
MEMTOTAL=`cat /proc/meminfo|grep MemTotal|awk '{print $(NF-1)}'`
MEMUSEDRAW=`free -k|grep 'Mem:'|awk '{print $(3)}'`
MEMCACHED=`cat /proc/meminfo|grep '^Cached:'|awk '{print $(NF-1)}'`
MEMFREE=$(awk "BEGIN {print ${MEMTOTAL} - ${MEMUSEDRAW} + ${MEMCACHED}}")
MEMUSED=$(awk "BEGIN {print ${MEMTOTAL} - ${MEMFREE}}")
MEMUSEDPCTFLOAT=$(awk "BEGIN {print ${MEMUSED} * 100 / ${MEMTOTAL}}")
MEMUSEDPCT=${MEMUSEDPCTFLOAT%.*}
SWAPTOTAL=`cat /proc/meminfo|grep SwapTotal|awk '{print $(NF-1)}'`
SWAPFREE=`cat /proc/meminfo|grep SwapFree|awk '{print $(NF-1)}'`
SWAPUSED=$(awk "BEGIN {print ${SWAPTOTAL} - ${SWAPFREE}}")
SWAPUSEDPCTFLOAT=$(awk "BEGIN {print ${SWAPUSED} * 100 / ${SWAPTOTAL}}")
SWAPUSEDPCT=${SWAPUSEDPCTFLOAT%.*}
fi
# IF LINUX VERSION IS 7 OR HIGHER:
if [ ${LNXVER} -ge 7 ]
then
MEMTOTAL=`cat /proc/meminfo|grep MemTotal|awk '{print $(NF-1)}'`
MEMUSEDRAW=`free -k|grep 'Mem:'|awk '{print $(3)}'`
MEMCACHED=`cat /proc/meminfo|grep '^Cached:'|awk '{print $(NF-1)}'`
MEMFREE=`cat /proc/meminfo|grep MemAvailable|awk '{print $(NF-1)}'`
MEMUSED=$(awk "BEGIN {print ${MEMTOTAL} - ${MEMFREE}}")
MEMUSEDPCTFLOAT=$(awk "BEGIN {print ${MEMUSED} * 100 / ${MEMTOTAL}}")
MEMUSEDPCT=${MEMUSEDPCTFLOAT%.*}
SWAPTOTAL=`cat /proc/meminfo|grep SwapTotal|awk '{print $(NF-1)}'`
SWAPFREE=`cat /proc/meminfo|grep SwapFree|awk '{print $(NF-1)}'`
SWAPUSED=$(awk "BEGIN {print ${SWAPTOTAL} - ${SWAPFREE}}")
SWAPUSEDPCTFLOAT=$(awk "BEGIN {print ${SWAPUSED} * 100 / ${SWAPTOTAL}}")
SWAPUSEDPCT=${SWAPUSEDPCTFLOAT%.*}
fi
# Show MEMORY ALERT if both MEMUSEDPCT and SWAPUSEDPCT are below their defined thresholds:
if [ ${MEMUSEDPCT} -ge ${USEDPHYSICALMEM_PCT} ] && [ ${SWAPUSEDPCT} -ge ${USEDSWAPMEM_PCT} ]
then
echo "" >> ${OS_HEALTHCHK_RPT}
echo "^^^^^^^^^^^^^^^^^" >> ${OS_HEALTHCHK_RPT}
echo "MEMORY_WARNING: " >> ${OS_HEALTHCHK_RPT}
echo "^^^^^^^^^^^^^^^^^" >> ${OS_HEALTHCHK_RPT}
echo "Looks_The_Server_Is_Running_Out_of_Memory!." >> ${OS_HEALTHCHK_RPT}
echo "" >> ${OS_HEALTHCHK_RPT}
echo "%USED_PHYSICAL_RAM:${MEMUSEDPCT}%" >> ${OS_HEALTHCHK_RPT}
echo "%USED_SWAP_SPACE:${SWAPUSEDPCT}%" >> ${OS_HEALTHCHK_RPT}
echo "" >> ${OS_HEALTHCHK_RPT}
echo "Memory_Details:" >> ${OS_HEALTHCHK_RPT}
echo "^^^^^^^^^^^^^^" >> ${OS_HEALTHCHK_RPT}
echo "" >> ${OS_HEALTHCHK_RPT}
free -g >> ${OS_HEALTHCHK_RPT}
echo "" >> ${OS_HEALTHCHK_RPT}
mail -s "ALARM: OUT OF MEMORY Scenario is Imminent on Server [${SRV_NAME}]" ${MAIL_LIST} < ${OS_HEALTHCHK_RPT}
fi
fi
;;
esac
# Show yesterday's hardware stats if crossed threshold:
case ${SHOW_YESTERDAY_STATS} in
Y|y|YES|Yes|yes|ON|On|on)
# Yesterday's High CPU Utilization:
# #################################
# If CPU IDLE is below 5% or CPU Utilization is higher than 95%:
HIGH_CPU_CNT=`sar -f /var/log/sa/sa$(date +%d -d yesterday) | sed -r '/^\s*$/d' | awk '{ if ( $NF < 5 ) print $NF,$1,$2 }'|wc -l`
if [ ${HIGH_CPU_CNT} -gt 1 ]
then
echo "" >> ${OS_HEALTHCHK_RPT}
echo "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" >> ${OS_HEALTHCHK_RPT}
echo "Yesterday's_High_CPU_Periods:" >> ${OS_HEALTHCHK_RPT}
echo "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" >> ${OS_HEALTHCHK_RPT}
sar -f /var/log/sa/sa$(date +%d -d yesterday) | sed -r '/^\s*$/d' | grep -v Linux | awk '{ if ( $NF < 5 ) print $NF,$1,$2 }' >> ${OS_HEALTHCHK_RPT}
fi
# Yesterday's High Memory Utilization:
# ####################################
# If Memory utilization cross 95%:
HIGH_MEM_CNT=`sar -r -f /var/log/sa/sa$(date +%d -d yesterday) | grep -Ev 'Average|Linux' | awk '{ if ( $5 > 95 ) print $5,$1,$2 }'|wc -l`
if [ ${HIGH_MEM_CNT} -ge 1 ]
then
echo "" >> ${OS_HEALTHCHK_RPT}
echo "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" >> ${OS_HEALTHCHK_RPT}
echo "Yesterday's_High_Memory_Periods:" >> ${OS_HEALTHCHK_RPT}
echo "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" >> ${OS_HEALTHCHK_RPT}
sar -r -f /var/log/sa/sa$(date +%d -d yesterday) | grep -Ev 'Average|Linux' | awk '{ if ( $5 > 95 ) print $5,$1,$2 }' >> ${OS_HEALTHCHK_RPT}
fi
;;
esac
# Filesystem Utilization:
# #######################
echo "" >> ${OS_HEALTHCHK_RPT}
echo "^^^^^^^^^^^^^^^^^" >> ${OS_HEALTHCHK_RPT}
echo "Local_Filesystem:" >> ${OS_HEALTHCHK_RPT}
echo "^^^^^^^^^^^^^^^^^" >> ${OS_HEALTHCHK_RPT}
${DF} >> ${OS_HEALTHCHK_RPT}
echo "" >> ${OS_HEALTHCHK_RPT}
sed -i 's/Mounted on/Mounted_on/g' ${OS_HEALTHCHK_RPT}
# ############################################
# Checking RAC/ORACLE_RESTART Services:
# ############################################
case ${CHECK_CLUSTER} in
y|Y|yes|YES|Yes|ON|On|on)
# Check for ocssd clusterware process:
CHECK_OCSSD=`ps -ef|grep 'ocssd.bin'|grep -v grep|wc -l`
CHECK_CRSD=`ps -ef|grep 'crsd.bin'|grep -v grep|wc -l`
if [ ${CHECK_CRSD} -gt 0 ]
then
CLS_STR=crs
export CLS_STR
CLUSTER_TYPE=CLUSTERWARE
export CLUSTER_TYPE
else
CLS_STR=has
export CLS_STR
CLUSTER_TYPE=ORACLE_RESTART
export CLUSTER_TYPE
fi
if [ ${CHECK_CRSD} -gt 0 ]
then
GRID_HOME=`ps -ef|grep 'ocssd.bin'|grep -v grep|awk '{print $NF}'|sed -e 's/\/bin\/ocssd.bin//g'|grep -v sed|grep -v "//g"`
export GRID_HOME
echo "^^^^^^^^^^^^^^^^^^^" >> ${OS_HEALTHCHK_RPT}
echo "CLUSTERWARE CHECKS:" >> ${OS_HEALTHCHK_RPT}
echo "^^^^^^^^^^^^^^^^^^^" >> ${OS_HEALTHCHK_RPT}
echo "" >> ${OS_HEALTHCHK_RPT}
FILE_NAME=${GRID_HOME}/bin/ocrcheck
export FILE_NAME
if [ -x ${FILE_NAME} ]
then
echo "" >> ${OS_HEALTHCHK_RPT}
echo "^^^^^^^^^^^^^^^^^^^" >> ${OS_HEALTHCHK_RPT}
echo "OCR DISKS CHECKING:" >> ${OS_HEALTHCHK_RPT}
echo "^^^^^^^^^^^^^^^^^^^" >> ${OS_HEALTHCHK_RPT}
${GRID_HOME}/bin/ocrcheck >> ${OS_HEALTHCHK_RPT}
echo "" >> ${OS_HEALTHCHK_RPT}
fi
FILE_NAME=${GRID_HOME}/bin/crsctl
export FILE_NAME
if [ -x ${FILE_NAME} ]
then
echo "" >> ${OS_HEALTHCHK_RPT}
echo "^^^^^^^^^^^^^^^^^^^^" >> ${OS_HEALTHCHK_RPT}
echo "VOTE DISKS CHECKING:" >> ${OS_HEALTHCHK_RPT}
echo "^^^^^^^^^^^^^^^^^^^^" >> ${OS_HEALTHCHK_RPT}
${GRID_HOME}/bin/crsctl query css votedisk >> ${OS_HEALTHCHK_RPT}
echo "" >> ${OS_HEALTHCHK_RPT}
fi
fi
if [ ${CHECK_OCSSD} -gt 0 ]
then
GRID_HOME=`ps -ef|grep 'ocssd.bin'|grep -v grep|awk '{print $NF}'|sed -e 's/\/bin\/ocssd.bin//g'|grep -v sed|grep -v "//g"`
export GRID_HOME
FILE_NAME=${GRID_HOME}/bin/crsctl
export FILE_NAME
if [ -x ${FILE_NAME} ]
then
echo "" >> ${OS_HEALTHCHK_RPT}
echo "" >> ${OS_HEALTHCHK_RPT}
echo "^^^^^^^^^^^^^^^^^^^^^^^" >> ${OS_HEALTHCHK_RPT}
echo "${CLUSTER_TYPE}_SERVICES:" >> ${OS_HEALTHCHK_RPT}
echo "^^^^^^^^^^^^^^^^^^^^^^^" >> ${OS_HEALTHCHK_RPT}
EXCLUDED_SERVICES="ora.proxy_advm|ora.asmgroup|ora.diskmon|ora.ons"
$GRID_HOME/bin/crsctl status res |grep -v "^$"|awk -F "=" 'BEGIN {print " "} {printf("%s",NR%4 ? $2"|" : $2"\n")}'|sed -e 's/ *, /,/g' -e 's/, /,/g'|\
awk -F "|" 'BEGIN { printf "%-50s%-50s\n","Resource_Name","State";printf "%-50s%-50s\n", "-------------------------------------","---------------------"; }{ split ($3,trg,",") split ($4,st,",")} {for (i in trg) {printf "%-50s%-50s\n",$1,st[i]}}'|egrep -v "${EXCLUDED_SERVICES}" >> ${OS_HEALTHCHK_RPT}
fi
FILE_NAME=${ORACLE_HOME}/bin/srvctl
export FILE_NAME
if [ -x ${FILE_NAME} ]
then
echo "" >> ${OS_HEALTHCHK_RPT}
echo "^^^^^^^^^^^^^^^^^^^^^^^^" >> ${OS_HEALTHCHK_RPT}
echo "DATABASE_SERVICES_STATUS:" >> ${OS_HEALTHCHK_RPT}
echo "^^^^^^^^^^^^^^^^^^^^^^^^" >> ${OS_HEALTHCHK_RPT}
${ORACLE_HOME}/bin/srvctl status service -d ${DB_UNQ_NAME} >> ${OS_HEALTHCHK_RPT}
echo "" >> ${OS_HEALTHCHK_RPT}
fi
fi
;;
esac
echo "" >> ${OS_HEALTHCHK_RPT}
echo "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" >> ${OS_HEALTHCHK_RPT}
echo "List_of_All_Running_Instances:" >> ${OS_HEALTHCHK_RPT}
echo "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" >> ${OS_HEALTHCHK_RPT}
ps -ef|grep pmon|grep -v grep >> ${OS_HEALTHCHK_RPT}
echo "" >> ${OS_HEALTHCHK_RPT}
echo "" >> ${OS_HEALTHCHK_RPT}
echo "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" >> ${OS_HEALTHCHK_RPT}
echo "List_of_All_Running_Listeners:" >> ${OS_HEALTHCHK_RPT}
echo "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" >> ${OS_HEALTHCHK_RPT}
ps -ef|grep tnslsnr|grep -v grep >> ${OS_HEALTHCHK_RPT}
echo "" >> ${OS_HEALTHCHK_RPT}
# https://superuser.com/questions/529830/get-a-list-of-open-ports-in-linux [datashaman]
FILE_NAME=/bin/netstat
export FILE_NAME
if [ -x ${FILE_NAME} ]
then
echo "" >> ${OS_HEALTHCHK_RPT}
echo "^^^^^^^^^^^^^^^^^^^^^^^" >> ${OS_HEALTHCHK_RPT}
echo "List_of_All_Open_Ports:" >> ${OS_HEALTHCHK_RPT}
echo "^^^^^^^^^^^^^^^^^^^^^^^" >> ${OS_HEALTHCHK_RPT}
netstat -lnt | awk 'NR>2{print $4}' | grep -E '(0.0.0.0:|:::)' | sed 's/.*://' | sort -n | uniq >> ${OS_HEALTHCHK_RPT}
echo "" >> ${OS_HEALTHCHK_RPT}
fi
# Convert OS Checks into HTML format:
#${HASHHTMLOS} awk 'BEGIN { print ""} {print ""; for(i=1;i<=NF;i++)print "" $i" | "; print "
"} END{print "
" }' ${OS_HEALTHCHK_RPT} >> ${DB_HEALTHCHK_RPT}
case ${HASHHTMLOS} in
'echo #')
cat ${OS_HEALTHCHK_RPT} >> ${DB_HEALTHCHK_RPT};;
*)
${HASHHTMLOS} awk 'BEGIN { print ""} {print ""; for(i=1;i<=NF;i++)print "" $i" | "; print "
"} END{print "
" }' ${OS_HEALTHCHK_RPT} >> ${DB_HEALTHCHK_RPT};;
esac
# ############################################
# REPORT UNRECOVERABLE DATABASE FILES: [RMAN]
# ############################################
case ${REPORTUNRECOVERABLE} in
Y|y|YES|Yes|yes|ON|On|on)
VAL37=$(${ORACLE_HOME}/bin/rman target / << EOF
spool log to ${LOG_DIR}/unrecoverable_DBfiles.log;
REPORT UNRECOVERABLE;
spool log off;
exit;
EOF
)
#${HASHHTMLOS} echo "" > ${LOG_DIR}/unrecoverable_DBfiles_FORMATTED.log
#${HASHHTMLOS} echo "" > ${LOG_DIR}/unrecoverable_DBfiles_FORMATTED.log
#${HASHHTMLOS} echo "UNRECOVERABLE_DATABASE_FILES:RMAN" >> ${LOG_DIR}/unrecoverable_DBfiles_FORMATTED.log
#${HASHHTMLOS} echo "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" >> ${LOG_DIR}/unrecoverable_DBfiles_FORMATTED.log
#${HASHHTMLOS} sed '/Spooling \|Recovery Manager\|RMAN>\|using \|Report \|^$/d' ${LOG_DIR}/unrecoverable_DBfiles.log >> ${LOG_DIR}/unrecoverable_DBfiles_FORMATTED.log
#${HASHHTMLOS} awk 'BEGIN { print ""} {print ""; for(i=1;i<=NF;i++)print "" $i" | "; print "
"} END{print "
" }' ${LOG_DIR}/unrecoverable_DBfiles_FORMATTED.log >> ${DB_HEALTHCHK_RPT}
;;
esac
# ############################################
# Checking Advisors:
# ############################################
# Checking if the Advisors should be enabled in the report:
case ${SHOWSQLTUNINGADVISOR} in
Y|y|YES|Yes|yes|ON|On|on)
export HASHSTA="";;
*)
export HASHSTA="--";;
esac
case ${SHOWMEMORYADVISORS} in
Y|y|YES|Yes|yes|ON|On|on)
export HASHMA="";;
*)
export HASHMA="--";;
esac
case ${SHOWSEGMENTADVVISOR} in
Y|y|YES|Yes|yes|ON|On|on)
export HASHSA="";;
*)
export HASHSA="--";;
esac
case ${REPORTUNRECOVERABLE} in
Y|y|YES|Yes|yes|ON|On|on)
export HASHU="";;
*)
export HASHU="--";;
esac
case ${SHOWJOBS} in
Y|y|YES|Yes|yes|ON|On|on)
export HASHJ="";;
*)
export HASHJ="--";;
esac
case ${SHOWHASHEDCRED} in
Y|y|YES|Yes|yes|ON|On|on)
export HASHCRD="";;
*)
export HASHCRD="--";;
esac
case ${SHOWDORMANTACCOUNTS} in
Y|y|YES|Yes|yes|ON|On|on)
export HASHDORM="";;
*)
export HASHDORM="--";;
esac
# If the database version is 10g onward collect the advisors recommendations:
if [ ${DB_VER} -gt 9 ]
then
VAL611=$(${ORACLE_HOME}/bin/sqlplus -S "/ as sysdba" << EOF
set linesize ${SQLLINESIZE} pages 100
-- Enable HTML color format:
--${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD ' ' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD ' ' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
spool ${DB_HEALTHCHK_RPT} app
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT Tablespaces Size
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} PROMPT
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^
${HASHNONHTML} PROMPT Tablespaces Size: [Based on Datafiles MAXSIZE]
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^
set pages 1000 linesize ${SQLLINESIZE} tab off
col tablespace_name for A25
col Total_MB for 999999999999
col Used_MB for 999999999999
col '%Used' for 999.99
comp sum of Total_MB on report
comp sum of Used_MB on report
bre on report
select tablespace_name,
(tablespace_size*$blksize)/(1024*1024) Total_MB,
(used_space*$blksize)/(1024*1024) Used_MB,
-- used_percent "%Used"
${HASHHTML} case when used_percent > 90 then '' || to_char(used_percent,999.99) || '' else to_char(used_percent,999.99) end as "%Used"
${HASHNONHTML} to_char(used_percent,999.99) "%Used"
from dba_tablespace_usage_metrics;
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT ASM STATISTICS
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^
${HASHNONHTML} PROMPT ASM STATISTICS:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^
select name,state,OFFLINE_DISKS,total_mb,free_mb,
${HASHHTML} case when ROUND((1-(free_mb / total_mb))*100, 2) > 90 then '' || to_char(ROUND((1-(free_mb / total_mb))*100, 2),999.99) || '' else to_char(ROUND((1-(free_mb / total_mb))*100, 2),999.99) end as "%FULL"
${HASHNONHTML} to_char(ROUND((1-(free_mb / total_mb))*100, 2),999.99) "%FULL"
from v\$asm_diskgroup;
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT FRA STATISTICS
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^
${HASHNONHTML} PROMPT FRA STATISTICS:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT FRA SIZE
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} PROMPT
${HASHNONHTML} PROMPT FRA_SIZE:
${HASHNONHTML} PROMPT ^^^^^^^^^
col name for a35
SELECT NAME,NUMBER_OF_FILES,SPACE_LIMIT/1024/1024/1024 AS TOTAL_SIZE_GB,SPACE_USED/1024/1024/1024 SPACE_USED_GB,
SPACE_RECLAIMABLE/1024/1024/1024 SPACE_RECLAIMABLE_GB,ROUND((SPACE_USED-SPACE_RECLAIMABLE)/SPACE_LIMIT * 100, 1) AS "%FULL_AFTER_CLAIM",
${HASHHTML} case when ROUND((SPACE_USED)/SPACE_LIMIT * 100, 1) > 90 then '' || to_char(ROUND((SPACE_USED)/SPACE_LIMIT * 100, 1),999.99) || '' else to_char(ROUND((SPACE_USED)/SPACE_LIMIT * 100, 1),999.99) end as "%FULL_NOW"
${HASHNONHTML} to_char(ROUND((SPACE_USED)/SPACE_LIMIT * 100, 1),999.99) "%FULL_NOW"
FROM V\$RECOVERY_FILE_DEST;
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT FRA COMPONENTS
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} PROMPT FRA_COMPONENTS:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^
select * from v\$flash_recovery_area_usage;
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT DATABASE GROWTH
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^
${HASHNONHTML} PROMPT DATABASE GROWTH: [In the Last ~8 days]
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD ' ' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
set serveroutput on
col SNAP_TIME for a45
col "Database Size(GB)" for 99999999999999999
Declare
v_BaselineSize number(20);
v_CurrentSize number(20);
v_TotalGrowth number(20);
v_Space number(20);
cursor usageHist is
select a.snap_id,
SNAP_TIME,
sum(TOTAL_SPACE_ALLOCATED_DELTA) over ( order by a.SNAP_ID) ProgSum
from
(select SNAP_ID,
sum(SPACE_ALLOCATED_DELTA) TOTAL_SPACE_ALLOCATED_DELTA
from DBA_HIST_SEG_STAT
group by SNAP_ID
having sum(SPACE_ALLOCATED_TOTAL) <> 0
order by 1 ) a,
(select distinct SNAP_ID,
to_char(END_INTERVAL_TIME,'DD-Mon-YYYY HH24:Mi') SNAP_TIME
from DBA_HIST_SNAPSHOT) b
where a.snap_id=b.snap_id;
Begin
select sum(SPACE_ALLOCATED_DELTA) into v_TotalGrowth from DBA_HIST_SEG_STAT;
select sum(bytes) into v_CurrentSize from dba_segments;
v_BaselineSize := (v_CurrentSize - v_TotalGrowth) ;
dbms_output.put_line('SNAP_TIME Database Size(GB)');
for row in usageHist loop
v_Space := (v_BaselineSize + row.ProgSum)/(1024*1024*1024);
dbms_output.put_line(row.SNAP_TIME || ' ' || to_char(v_Space) );
end loop;
end;
/
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT Active Incidents
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} PROMPT
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^
${HASHNONHTML} PROMPT Active Incidents:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^
set linesize ${SQLLINESIZE}
col RECENT_PROBLEMS_1_WEEK_BACK for a45
select PROBLEM_KEY RECENT_PROBLEMS_1_WEEK_BACK,to_char(FIRSTINC_TIME,'DD-MON-YY HH24:mi:ss') FIRST_OCCURENCE,to_char(LASTINC_TIME,'DD-MON-YY HH24:mi:ss')
LAST_OCCURENCE FROM V\$DIAG_PROBLEM WHERE LASTINC_TIME > SYSDATE -10;
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT OUTSTANDING ALERTS
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} PROMPT
${HASHNONHTML} PROMPT OUTSTANDING ALERTS:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^
col CREATION_TIME for a40
col REASON for a80
select REASON,CREATION_TIME,METRIC_VALUE from DBA_OUTSTANDING_ALERTS;
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT CORRUPTED BLOCKS
${HASHHTML} PROMPT |
${HASHHTML} set pages 1000
${HASHNONHTML} PROMPT
${HASHNONHTML} PROMPT CORRUPTED BLOCKS:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^
select * from V\$DATABASE_BLOCK_CORRUPTION;
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT BLOCKED SESSIONS
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} PROMPT
${HASHNONHTML} PROMPT BLOCKED SESSIONS:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^
col module for a27
col event for a24
col MACHINE for a27
col "WA_ST|WAITD|ACT_SINC|LOG_T" for a38
col "INST|USER|SID,SERIAL#" for a30
col "INS|USER|SID,SER|MACHIN|MODUL" for a65
col "PREV|CURR SQLID" for a27
col "I|BLKD_BY" for a12
select /*+RULE*/
substr(s.INST_ID||'|'||s.USERNAME||'| '||s.sid||','||s.serial#||' |'||substr(s.MACHINE,1,22)||'|'||substr(s.MODULE,1,18),1,65)"INS|USER|SID,SER|MACHIN|MODUL"
,substr(w.state||'|'||round(w.WAIT_TIME_MICRO/1000000)||'|'||LAST_CALL_ET||'|'||to_char(LOGON_TIME,'ddMon'),1,38) "WA_ST|WAITD|ACT_SINC|LOG_T"
,substr(w.event,1,24) "EVENT"
,s.FINAL_BLOCKING_INSTANCE||'|'||s.FINAL_BLOCKING_SESSION "I|BLKD_BY"
from gv\$session s, gv\$session_wait w
where s.USERNAME is not null
and s.FINAL_BLOCKING_SESSION is not null
and s.sid=w.sid
and s.STATUS='ACTIVE'
order by "I|BLKD_BY" desc,w.event,"INS|USER|SID,SER|MACHIN|MODUL","WA_ST|WAITD|ACT_SINC|LOG_T" desc;
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT UN-USABLE INDEXES
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} PROMPT
${HASHNONHTML} PROMPT UN-USABLE INDEXES:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^
PROMPT
col REBUILD_UNUSABLE_INDEXES for a190
${HASHNONHTML} set echo on feedback on pages 1000
${HASHNONHTML} select 'ALTER INDEX '||OWNER||'.'||INDEX_NAME||' REBUILD ONLINE;' REBUILD_UNUSABLE_INDEXES from dba_indexes where status='UNUSABLE';
${HASHHTML} select OWNER,INDEX_NAME from dba_indexes where status='UNUSABLE';
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT INVALID OBJECTS
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} PROMPT
${HASHNONHTML} PROMPT INVALID OBJECTS:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^
${HASHNONHTML} PROMPT
set pages 0
select 'alter package '||owner||'.'||object_name||' compile;' from dba_objects where status <> 'VALID' and object_type like '%PACKAGE%' union
select 'alter type '||owner||'.'||object_name||' compile specification;' from dba_objects where status <> 'VALID' and object_type like '%TYPE%'union
select 'alter '||object_type||' '||owner||'.'||object_name||' compile;' from dba_objects where status <> 'VALID' and object_type not in ('PACKAGE','PACKAGE BODY','SYNONYM','TYPE','TYPE BODY') union
select 'alter public synonym '||object_name||' compile;' from dba_objects where status <> 'VALID' and object_type ='SYNONYM';
set pages 1000
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT RMAN BACKUP OPERATIONS
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} PROMPT
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^^^^^
${HASHNONHTML} PROMPT RMAN BACKUP OPERATIONS: [LAST 24H]
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^^^^^
col START_TIME for a15
col END_TIME for a15
col TIME_TAKEN_DISPLAY for a10
col INPUT_BYTES_DISPLAY heading "DATA SIZE" for a10
col OUTPUT_BYTES_DISPLAY heading "Backup Size" for a11
col OUTPUT_BYTES_PER_SEC_DISPLAY heading "Speed/s" for a10
col output_device_type heading "Device_TYPE" for a11
SELECT to_char (start_time,'DD-MON-YY HH24:MI') START_TIME, to_char(end_time,'DD-MON-YY HH24:MI') END_TIME, time_taken_display,
${HASHHTML} case when status not in ('COMPLETED','RUNNING') then '' || to_char(status) || '' else to_char(status) end as "status",
${HASHNONHTML} status
input_type, output_device_type,input_bytes_display, output_bytes_display, output_bytes_per_sec_display ,COMPRESSION_RATIO
FROM v\$rman_backup_job_details
WHERE end_time > sysdate -1;
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} ${HASHU}PROMPT
${HASHHTML} ${HASHU}PROMPT REPORT UNRECOVERABLE DATAFILES
${HASHHTML} ${HASHU}PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} ${HASHU}PROMPT
${HASHNONHTML} ${HASHU}PROMPT ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
${HASHNONHTML} ${HASHU}PROMPT REPORT UNRECOVERABLE DATAFILES:
${HASHNONHTML} ${HASHU}PROMPT ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
${HASHU}spool off
--${HASHU}host sed '/Spooling \|Recovery Manager\|RMAN>\|^$/d' ${LOG_DIR}/unrecoverable_DBfiles.log >> ${DB_HEALTHCHK_RPT}
${HASHU}host sed '/Spooling \|Recovery Manager\|RMAN>\|using \|Report \|^$/d' ${LOG_DIR}/unrecoverable_DBfiles.log >> ${DB_HEALTHCHK_RPT}
--${HASHU}host ${HASHNOHTMLOS} sed '/Spooling \|Recovery Manager\|RMAN>\|^$/d' ${LOG_DIR}/unrecoverable_DBfiles.log >> ${DB_HEALTHCHK_RPT}
--${HASHU}host ${HASHHTMLOS} sed '/Spooling \|Recovery Manager\|RMAN>\|using \|Report \|^$/d' ${LOG_DIR}/unrecoverable_DBfiles.log > ${LOG_DIR}/unrecoverable_DBfiles_FORMATTED.log
--${HASHU}host ${HASHHTMLOS} awk 'BEGIN { print ""} {print ""; for(i=1;i<=NF;i++)print "" $i" | "; print "
"} END{print "
" }' ${LOG_DIR}/unrecoverable_DBfiles_FORMATTED.log > ${LOG_DIR}/unrecoverable_DBfiles_HTML.log
--${HASHU}host ${HASHHTMLOS} cat ${LOG_DIR}/unrecoverable_DBfiles_HTML.log >> ${DB_HEALTHCHK_RPT}
${HASHU}spool ${DB_HEALTHCHK_RPT} app
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} ${HASHJ}PROMPT
${HASHHTML} ${HASHJ}PROMPT SCHEDULED JOBS STATUS
${HASHHTML} ${HASHJ}PROMPT |
${HASHHTML} ${HASHJ}PROMPT
${HASHHTML} ${HASHJ}PROMPT DBMS_JOBS
${HASHHTML} ${HASHJ}PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} ${HASHJ}PROMPT
${HASHNONHTML} ${HASHJ}PROMPT ^^^^^^^^^^^^^^^^^^^^^^
${HASHNONHTML} ${HASHJ}PROMPT SCHEDULED JOBS STATUS:
${HASHNONHTML} ${HASHJ}PROMPT ^^^^^^^^^^^^^^^^^^^^^^
${HASHNONHTML} ${HASHJ}PROMPT
${HASHNONHTML} ${HASHJ}PROMPT DBMS_JOBS:
${HASHNONHTML} ${HASHJ}PROMPT ^^^^^^^^^^
${HASHJ}set linesize ${SQLLINESIZE}
${HASHJ}col LAST_RUN for a25
${HASHJ}col NEXT_RUN for a25
${HASHJ}select job,schema_user,failures,to_char(LAST_DATE,'DD-Mon-YYYY hh24:mi:ss')LAST_RUN,to_char(NEXT_DATE,'DD-Mon-YYYY hh24:mi:ss')NEXT_RUN from dba_jobs;
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} ${HASHJ}PROMPT
${HASHHTML} ${HASHJ}PROMPT DBMS_SCHEDULER
${HASHHTML} ${HASHJ}PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} ${HASHJ}PROMPT
${HASHNONHTML} ${HASHJ}PROMPT DBMS_SCHEDULER:
${HASHNONHTML} ${HASHJ}PROMPT ^^^^^^^^^^^^^^^
${HASHJ}col OWNER for a15
${HASHJ}col JOB_NAME for a30
${HASHJ}col STATE for a15
${HASHJ}col FAILURE_COUNT for 9999 heading 'Fail'
${HASHJ}col "DURATION(d:hh:mm:ss)" for a22
${HASHJ}col REPEAT_INTERVAL for a70
${HASHJ}col "LAST_RUN || REPEAT_INTERVAL" for a65
${HASHJ}col "DURATION(d:hh:mm:ss)" for a12
${HASHJ}select JOB_NAME,OWNER,ENABLED,STATE,
${HASHJ} ${HASHHTML} case when FAILURE_COUNT > 0 then '' || to_char(FAILURE_COUNT,99999) || '' else to_char(FAILURE_COUNT,99999) end as "FAILURE_COUNT",
${HASHJ} ${HASHNONHTML} FAILURE_COUNT,
${HASHJ}to_char(LAST_START_DATE,'DD-Mon-YYYY hh24:mi:ss')||' || '||REPEAT_INTERVAL "LAST_RUN || REPEAT_INTERVAL",
${HASHJ}extract(day from last_run_duration) ||':'||
${HASHJ}lpad(extract(hour from last_run_duration),2,'0')||':'||
${HASHJ}lpad(extract(minute from last_run_duration),2,'0')||':'||
${HASHJ}lpad(round(extract(second from last_run_duration)),2,'0') "DURATION(d:hh:mm:ss)"
${HASHJ}from dba_scheduler_jobs order by ENABLED,STATE;
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} ${HASHJ}PROMPT
${HASHHTML} ${HASHJ}PROMPT AUTOTASK INTERNAL MAINTENANCE WINDOWS
${HASHHTML} ${HASHJ}PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} ${HASHJ}PROMPT
${HASHNONHTML} ${HASHJ}PROMPT AUTOTASK INTERNAL MAINTENANCE WINDOWS:
${HASHNONHTML} ${HASHJ}PROMPT ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
${HASHJ}col WINDOW_NAME for a17
${HASHJ}col NEXT_RUN for a20
${HASHJ}col ACTIVE for a6
${HASHJ}col OPTIMIZER_STATS for a15
${HASHJ}col SEGMENT_ADVISOR for a15
${HASHJ}col SQL_TUNE_ADVISOR for a16
${HASHJ}SELECT WINDOW_NAME,TO_CHAR(WINDOW_NEXT_TIME,'DD-MM-YYYY HH24:MI:SS') NEXT_RUN,AUTOTASK_STATUS STATUS,WINDOW_ACTIVE ACTIVE,OPTIMIZER_STATS,SEGMENT_ADVISOR,SQL_TUNE_ADVISOR FROM DBA_AUTOTASK_WINDOW_CLIENTS;
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} ${HASHJ}PROMPT
${HASHHTML} ${HASHJ}PROMPT Current Running Jobs
${HASHHTML} ${HASHJ}PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} ${HASHJ}PROMPT
${HASHNONHTML} ${HASHJ}PROMPT Current Running Jobs:
${HASHNONHTML} ${HASHJ}PROMPT ^^^^^^^^^^^^^^^^^^^^
${HASHJ}col INS for 999
${HASHJ}col "JOB_NAME|OWNER|SPID|SID" for a55
${HASHJ}col ELAPSED_TIME for a17
${HASHJ}col CPU_USED for a17
${HASHJ}col "WAIT_SEC" for 9999999999
${HASHJ}col WAIT_CLASS for a15
${HASHJ}col "BLKD_BY" for 9999999
${HASHJ}col "WAITED|WCLASS|EVENT" for a45
${HASHJ}select j.RUNNING_INSTANCE INS,j.JOB_NAME ||' | '|| j.OWNER||' |'||SLAVE_OS_PROCESS_ID||'|'||j.SESSION_ID"JOB_NAME|OWNER|SPID|SID"
${HASHJ},s.FINAL_BLOCKING_SESSION "BLKD_BY",ELAPSED_TIME,CPU_USED
${HASHJ},substr(s.SECONDS_IN_WAIT||'|'||s.WAIT_CLASS||'|'||s.EVENT,1,45) "WAITED|WCLASS|EVENT",S.SQL_ID
${HASHJ}from dba_scheduler_running_jobs j, gv\$session s
${HASHJ}where j.RUNNING_INSTANCE=S.INST_ID(+)
${HASHJ}and j.SESSION_ID=S.SID(+)
${HASHJ}order by "JOB_NAME|OWNER|SPID|SID",ELAPSED_TIME;
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} ${HASHJ}PROMPT
${HASHHTML} ${HASHJ}PROMPT FAILED DBMS_SCHEDULER JOBS IN THE LAST 24H
${HASHHTML} ${HASHJ}PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} ${HASHJ}PROMPT
${HASHNONHTML} ${HASHJ}PROMPT FAILED DBMS_SCHEDULER JOBS IN THE LAST 24H:
${HASHNONHTML} ${HASHJ}PROMPT ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
${HASHJ}col LOG_DATE for a36
${HASHJ}col OWNER for a15
${HASHJ}col JOB_NAME for a35
${HASHJ}col STATUS for a11
${HASHJ}col RUN_DURATION for a20
${HASHJ}col ID for 99
${HASHJ}select INSTANCE_ID ID,JOB_NAME,OWNER,LOG_DATE,STATUS,ERROR#,RUN_DURATION from DBA_SCHEDULER_JOB_RUN_DETAILS where LOG_DATE > sysdate-1 and STATUS='FAILED' order by JOB_NAME,LOG_DATE;
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT Queries Running For More Than [${LONG_RUN_QUR_HOURS}] Hours
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
${HASHNONHTML} PROMPT Queries Running For More Than [${LONG_RUN_QUR_HOURS}] Hour:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
col module for a30
col DURATION_HOURS for 99999.9
col STARTED_AT for a13
col "USERNAME| SID,SERIAL#" for a30
${HASHNONHTML} col "SQL_ID | SQL_TEXT" for a120
select username||'| '||sid ||','|| serial# "USERNAME| SID,SERIAL#",substr(MODULE,1,30) "MODULE", to_char(sysdate-last_call_et/24/60/60,'DD-MON HH24:MI') STARTED_AT,
last_call_et/60/60 "DURATION_HOURS"
--||' | '|| (select SQL_FULLTEXT from v\$sql where address=sql_address) "SQL_ID | SQL_TEXT"
,SQL_ID
from v\$session where
username is not null
and module is not null
and module not in (${EXCLUDED_MODULES})
and last_call_et > 60*60*${LONG_RUN_QUR_HOURS}
and status = 'ACTIVE';
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} ${HASHSTA}PROMPT
${HASHHTML} ${HASHSTA}PROMPT ADVISORS STATUS
${HASHHTML} ${HASHSTA}PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^
${HASHNONHTML} PROMPT ADVISORS STATUS:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^
col ADVISOR_NAME for a60
col STATUS for a15
${HASHSTA}SELECT client_name ADVISOR_NAME, status FROM dba_autotask_client ORDER BY client_name;
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} ${HASHSTA}PROMPT
${HASHHTML} ${HASHSTA}PROMPT SQL TUNING ADVISOR
${HASHHTML} ${HASHSTA}PROMPT |
${HASHHTML} set pages 1000
${HASHNONHTML} ${HASHSTA}PROMPT
${HASHNONHTML} ${HASHSTA}PROMPT ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
${HASHNONHTML} ${HASHSTA}PROMPT SQL TUNING ADVISOR:
${HASHNONHTML} ${HASHSTA}PROMPT ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} ${HASHSTA}PROMPT
${HASHHTML} ${HASHSTA}PROMPT Last Execution of SQL TUNING ADVISOR
${HASHHTML} ${HASHSTA}PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} ${HASHSTA}PROMPT
${HASHNONHTML} ${HASHSTA}PROMPT Last Execution of SQL TUNING ADVISOR:
${HASHNONHTML} ${HASHSTA}PROMPT ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
${HASHSTA}col TASK_NAME for a60
${HASHSTA}set long 2000000000
${HASHSTA}SELECT task_name, status, TO_CHAR(execution_end,'DD-MON-YY HH24:MI') Last_Execution FROM dba_advisor_executions where TASK_NAME='SYS_AUTO_SQL_TUNING_TASK' and execution_end>sysdate-1;
${HASHSTA}variable Findings_Report CLOB;
${HASHSTA} BEGIN
${HASHSTA} :Findings_Report :=DBMS_SQLTUNE.REPORT_AUTO_TUNING_TASK(
${HASHSTA} begin_exec => NULL,
${HASHSTA} end_exec => NULL,
${HASHSTA} type => 'TEXT',
${HASHSTA} level => 'TYPICAL',
${HASHSTA} section => 'ALL',
${HASHSTA} object_id => NULL,
${HASHSTA} result_limit => NULL);
${HASHSTA} END;
${HASHSTA} /
${HASHSTA} print :Findings_Report
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} ${HASHMA}PROMPT
${HASHHTML} ${HASHMA}PROMPT MEMORY ADVISORS
${HASHHTML} ${HASHMA}PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} PROMPT
${HASHNONHTML} PROMPT
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
${HASHNONHTML} PROMPT ORACLE MEMORY UTILIZATION:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT ORACLE MEMORY UTILIZATION
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
col inst_id heading ins for 999
col COMPONENT for a35
col CURRENT_SIZE_MB for 99999999999
col MAX_SIZE_MB for 99999999999
select INST_ID,COMPONENT,USER_SPECIFIED_SIZE/1024/1024 USER_SPECIFIED_SIZE_MB,CURRENT_SIZE/1024/1024 CURRENT_SIZE_MB,MAX_SIZE/1024/1024 MAX_SIZE_MB from gv\$memory_dynamic_components where COMPONENT not like '%K buffer%' and COMPONENT not in ('ASM Buffer Cache','KEEP buffer cache','RECYCLE buffer cache','unified pga pool','Data Transfer Cache') order by COMPONENT,INST_ID;
${HASHNONHTML} ${HASHMA}PROMPT
${HASHNONHTML} ${HASHMA}PROMPT
${HASHNONHTML} ${HASHMA}PROMPT ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
${HASHNONHTML} ${HASHMA}PROMPT MEMORY ADVISORS:
${HASHNONHTML} ${HASHMA}PROMPT ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} ${HASHMA}PROMPT
${HASHHTML} ${HASHMA}PROMPT SGA ADVISOR
${HASHHTML} ${HASHMA}PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} ${HASHMA}PROMPT
${HASHNONHTML} ${HASHMA}PROMPT SGA ADVISOR:
${HASHNONHTML} ${HASHMA}PROMPT ^^^^^^^^^^^^
${HASHMA}col ESTD_DB_TIME for 99999999999999999
${HASHMA}col ESTD_DB_TIME_FACTOR for 9999999999999999999999999999
${HASHMA}select * from V\$SGA_TARGET_ADVICE where SGA_SIZE_FACTOR > .6 and SGA_SIZE_FACTOR < 1.6;
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} ${HASHMA}PROMPT
${HASHHTML} ${HASHMA}PROMPT Buffer Cache ADVISOR
${HASHHTML} ${HASHMA}PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} ${HASHMA}PROMPT
${HASHNONHTML} ${HASHMA}PROMPT Buffer Cache ADVISOR:
${HASHNONHTML} ${HASHMA}PROMPT ^^^^^^^^^^^^^^^^^^^^^
${HASHMA}col ESTD_SIZE_MB for 9999999999999
${HASHMA}col ESTD_PHYSICAL_READS for 99999999999999999999
${HASHMA}col ESTD_PHYSICAL_READ_TIME for 99999999999999999999
${HASHMA}select SIZE_FACTOR "%SIZE",SIZE_FOR_ESTIMATE ESTD_SIZE_MB,ESTD_PHYSICAL_READS,ESTD_PHYSICAL_READ_TIME,ESTD_PCT_OF_DB_TIME_FOR_READS
${HASHMA}from V\$DB_CACHE_ADVICE where SIZE_FACTOR >.8 and SIZE_FACTOR<1.3;
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} ${HASHMA}PROMPT
${HASHHTML} ${HASHMA}PROMPT Shared Pool ADVISOR
${HASHHTML} ${HASHMA}PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} ${HASHMA}PROMPT
${HASHNONHTML} ${HASHMA}PROMPT Shared Pool ADVISOR:
${HASHNONHTML} ${HASHMA}PROMPT ^^^^^^^^^^^^^^^^^^^^
${HASHMA}col SIZE_MB for 99999999999
${HASHMA}col SIZE_FACTOR for 99999999
${HASHMA}col ESTD_SIZE_MB for 99999999999999999999
${HASHMA}col LIB_CACHE_SAVED_TIME for 99999999999999999999999999
${HASHMA}select SHARED_POOL_SIZE_FOR_ESTIMATE SIZE_MB,SHARED_POOL_SIZE_FACTOR "%SIZE",SHARED_POOL_SIZE_FOR_ESTIMATE/1024/1024 ESTD_SIZE_MB,ESTD_LC_TIME_SAVED LIB_CACHE_SAVED_TIME,
${HASHMA}ESTD_LC_LOAD_TIME PARSING_TIME from V\$SHARED_POOL_ADVICE
${HASHMA}where SHARED_POOL_SIZE_FACTOR > .9 and SHARED_POOL_SIZE_FACTOR < 1.6;
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} ${HASHMA}PROMPT
${HASHHTML} ${HASHMA}PROMPT PGA ADVISOR
${HASHHTML} ${HASHMA}PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} ${HASHMA}PROMPT
${HASHNONHTML} ${HASHMA}PROMPT PGA ADVISOR:
${HASHNONHTML} ${HASHMA}PROMPT ^^^^^^^^^^^^
${HASHMA}col SIZE_FACTOR for 999999999
${HASHMA}col ESTD_SIZE_MB for 99999999999999999999
${HASHMA}col MB_PROCESSED for 99999999999999999999
${HASHMA}col ESTD_TIME for 99999999999999999999
${HASHMA}select PGA_TARGET_FACTOR "%SIZE",PGA_TARGET_FOR_ESTIMATE/1024/1024 ESTD_SIZE_MB,BYTES_PROCESSED/1024/1024 MB_PROCESSED,
${HASHMA}ESTD_TIME,ESTD_PGA_CACHE_HIT_PERCENTAGE PGA_HIT,ESTD_OVERALLOC_COUNT PGA_SHORTAGE
${HASHMA}from V\$PGA_TARGET_ADVICE where PGA_TARGET_FACTOR > .7 and PGA_TARGET_FACTOR < 1.6;
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} ${HASHSA}PROMPT
${HASHHTML} ${HASHSA}PROMPT SEGMENT ADVISOR
${HASHHTML} ${HASHSA}PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} ${HASHSA}PROMPT
${HASHNONHTML} ${HASHSA}PROMPT SEGMENT ADVISOR:
${HASHNONHTML} ${HASHSA}PROMPT ^^^^^^^^^^^^^^^^
${HASHSA}select'Task Name : ' || f.task_name || chr(10) ||
${HASHSA}'Start Run Time : ' || TO_CHAR(execution_start, 'dd-mon-yy hh24:mi') || chr (10) ||
${HASHSA}'Segment Name : ' || o.attr2 || chr(10) ||
${HASHSA}'Segment Type : ' || o.type || chr(10) ||
${HASHSA}'Partition Name : ' || o.attr3 || chr(10) ||
${HASHSA}'Message : ' || f.message || chr(10) ||
${HASHSA}'More Info : ' || f.more_info || chr(10) ||
${HASHSA}'-------------------------------------------' Advice
${HASHSA}FROM dba_advisor_findings f
${HASHSA},dba_advisor_objects o
${HASHSA},dba_advisor_executions e
${HASHSA}WHERE o.task_id = f.task_id
${HASHSA}AND o.object_id = f.object_id
${HASHSA}AND f.task_id = e.task_id
${HASHSA}AND e. execution_start > sysdate - 1
${HASHSA}AND e.advisor_name = 'Segment Advisor'
${HASHSA}ORDER BY f.task_name;
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^^^^^
${HASHNONHTML} PROMPT TOP FRAGMENTED TABLES:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^^^^^
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT TOP FRAGMENTED TABLES
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
col "%RECLAIMABLE_SPACE" for 99
col owner for a30
col "%FRAGMENTED_SPACE" for a17
col LAST_ANALYZED for a13
select * from (select owner,table_name,to_char(LAST_ANALYZED, 'DD-MON-YYYY') LAST_ANALYZED,
round(blocks * ${blksize}/1024/1024) "FULL_SIZE_MB",
round(num_rows * avg_row_len/1024/1024) "ACTUAL_SIZE_MB",
round(blocks * ${blksize}/1024/1024) - round(num_rows * avg_row_len/1024/1024) "FRAGMENTED_SPACE_MB",
round(((round((blocks * ${blksize}/1024/1024)) - round((num_rows * avg_row_len/1024/1024))) / round((blocks * ${blksize}/1024/1024))) * 100)||'%' "%FRAGMENTED_SPACE"
from dba_tables
where blocks>10
-- Exclude SYS objects:
and owner <> 'SYS'
and round(blocks * ${blksize}/1024/1024) > 10
-- Fragmented Space must be > 30%:
and ((round((blocks * ${blksize}/1024/1024)) - round((num_rows * avg_row_len/1024/1024))) / round((blocks * ${blksize}/1024/1024))) * 100 > 30
order by "FRAGMENTED_SPACE_MB" desc) where rownum<11;
PROMPT Hint: The accuracy of the FRAGMENTED TABLES list depends on having a recent STATISTICS.
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT CURRENT OS / HARDWARE STATISTICS
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
${HASHNONHTML} PROMPT CURRENT OS / HARDWARE STATISTICS:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
select stat_name,value from v\$osstat;
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT RESOURCE LIMIT
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} PROMPT
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^
${HASHNONHTML} PROMPT RESOURCE LIMIT:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^
col INITIAL_ALLOCATION for a20
col LIMIT_VALUE for a20
select * from gv\$resource_limit order by RESOURCE_NAME;
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT RECYCLEBIN OBJECTS#
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} PROMPT
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^^^
${HASHNONHTML} PROMPT RECYCLEBIN OBJECTS#: [Purging DBA_RECYCLEBIN can boost the performance of X$ tables]
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^^^
col "RECYCLED_OBJECTS#" for 999999999999999999
col "TOTAL_SIZE_MB" for 99999999999999
set feedback off
select
${HASHHTML} case when count(*) > 1000 then '' || to_char(count(*)) || '' else to_char(count(*)) end as "RECYCLED_OBJECTS#",
${HASHNONHTML} count(*) "RECYCLED_OBJECTS#",
${HASHHTML} case when sum(space)*${blksize}/1024/1024 > 1024 then '' || to_char(sum(space)*${blksize}/1024/1024) || '' else to_char(sum(space)*${blksize}/1024/1024) end as "TOTAL_SIZE_MB"
${HASHNONHTML} sum(space)*${blksize}/1024/1024 "TOTAL_SIZE_MB"
from dba_recyclebin group by 1;
set feedback on
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT FLASHBACK RESTORE POINTS
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} PROMPT
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^^^^^^^^
${HASHNONHTML} PROMPT FLASHBACK RESTORE POINTS:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^^^^^^^^
col SCN for 999999999999999999
col time for a35
col RESTORE_POINT_TIME for a35
col name for a40
select NAME,SCN,TIME,STORAGE_SIZE/1024/1024/1024 STORAGE_SIZE_GB from v\$restore_point;
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT HEALTH MONITOR
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} PROMPT
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^
${HASHNONHTML} PROMPT HEALTH MONITOR:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^
col DESCRIPTION for a80
col repair_script for a80
select name,type,status,description,repair_script from V\$HM_RECOMMENDATION where time_detected > sysdate -1;
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT Monitored INDEXES
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^
${HASHNONHTML} PROMPT Monitored INDEXES:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^
set linesize ${SQLLINESIZE} pages 1000
col Index_NAME for a40
col TABLE_NAME for a40
select io.name Index_NAME, t.name TABLE_NAME,decode(bitand(i.flags, 65536),0,'NO','YES') Monitoring,
decode(bitand(ou.flags, 1),0,'NO','YES') USED,ou.start_monitoring,ou.end_monitoring
from sys.obj$ io,sys.obj$ t,sys.ind$ i,sys.object_usage ou where i.obj# = ou.obj# and io.obj# = ou.obj# and t.obj# = i.bo#;
--PROMPT
--PROMPT To stop monitoring USED indexes use this command:
--prompt select 'ALTER INDEX RA.'||io.name||' NOMONITORING USAGE;' from sys.obj$ io,sys.obj$ t,sys.ind$ i,sys.object_usage ou where i.obj# = ou.obj# and io.obj# = ou.obj# and t.obj# = i.bo#
--prompt and decode(bitand(i.flags, 65536),0,'NO','YES')='YES' and decode(bitand(ou.flags, 1),0,'NO','YES')='YES' order by 1
--prompt /
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT REDO LOG SWITCHES
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} PROMPT
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^
${HASHNONHTML} PROMPT REDO LOG SWITCHES:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^
set linesize ${SQLLINESIZE}
col day for a11
SELECT to_char(first_time,'YYYY-MON-DD') day,
to_char(sum(decode(to_char(first_time,'HH24'),'00',1,0)),'9999') "00",
to_char(sum(decode(to_char(first_time,'HH24'),'01',1,0)),'9999') "01",
to_char(sum(decode(to_char(first_time,'HH24'),'02',1,0)),'9999') "02",
to_char(sum(decode(to_char(first_time,'HH24'),'03',1,0)),'9999') "03",
to_char(sum(decode(to_char(first_time,'HH24'),'04',1,0)),'9999') "04",
to_char(sum(decode(to_char(first_time,'HH24'),'05',1,0)),'9999') "05",
to_char(sum(decode(to_char(first_time,'HH24'),'06',1,0)),'9999') "06",
to_char(sum(decode(to_char(first_time,'HH24'),'07',1,0)),'9999') "07",
to_char(sum(decode(to_char(first_time,'HH24'),'08',1,0)),'9999') "08",
to_char(sum(decode(to_char(first_time,'HH24'),'09',1,0)),'9999') "09",
to_char(sum(decode(to_char(first_time,'HH24'),'10',1,0)),'9999') "10",
to_char(sum(decode(to_char(first_time,'HH24'),'11',1,0)),'9999') "11",
to_char(sum(decode(to_char(first_time,'HH24'),'12',1,0)),'9999') "12",
to_char(sum(decode(to_char(first_time,'HH24'),'13',1,0)),'9999') "13",
to_char(sum(decode(to_char(first_time,'HH24'),'14',1,0)),'9999') "14",
to_char(sum(decode(to_char(first_time,'HH24'),'15',1,0)),'9999') "15",
to_char(sum(decode(to_char(first_time,'HH24'),'16',1,0)),'9999') "16",
to_char(sum(decode(to_char(first_time,'HH24'),'17',1,0)),'9999') "17",
to_char(sum(decode(to_char(first_time,'HH24'),'18',1,0)),'9999') "18",
to_char(sum(decode(to_char(first_time,'HH24'),'19',1,0)),'9999') "19",
to_char(sum(decode(to_char(first_time,'HH24'),'20',1,0)),'9999') "20",
to_char(sum(decode(to_char(first_time,'HH24'),'21',1,0)),'9999') "21",
to_char(sum(decode(to_char(first_time,'HH24'),'22',1,0)),'9999') "22",
to_char(sum(decode(to_char(first_time,'HH24'),'23',1,0)),'9999') "23"
from v\$log_history where first_time > sysdate-1
GROUP by to_char(first_time,'YYYY-MON-DD') order by 1 asc;
${HASHHTML} PROMPT
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT Modified Parameters Since The Instance Startup
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} PROMPT
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
${HASHNONHTML} PROMPT Modified Parameters Since The Instance Startup:
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
col name for a45
col VALUE for a80
col DEPRECATED for a10
select NAME,VALUE,ISDEFAULT "DEFAULT",ISDEPRECATED "DEPRECATED" from v\$parameter where ISMODIFIED = 'SYSTEM_MOD' order by 1;
${HASHHTML} PROMPT
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} ${HASHCRD}PROMPT
${HASHHTML} ${HASHCRD}PROMPT Cred Backup
${HASHHTML} ${HASHCRD}PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} ${HASHCRD}PROMPT
${HASHNONHTML} ${HASHCRD}PROMPT ^^^^^^^^^^^^
${HASHNONHTML} ${HASHCRD}PROMPT Cred Backup:
${HASHNONHTML} ${HASHCRD}PROMPT ^^^^^^^^^^^^
${HASHCRD}col name for a35
${HASHCRD}col HASH for a35
${HASHCRD}col CREATION_DATE for a20
${HASHCRD}col PASSWORD_LAST_CHANGED for a30
${HASHCRD}col "CREATE_DATE||PASS_LAST_CHANGE" for a60
${HASHNONHTML} ${HASHCRD}select name,PASSWORD HASH,CTIME ||' || '||PTIME "CREATE_DATE||PASS_LAST_CHANGE" from user\$ where PASSWORD is not null order by 1;
${HASHHTML} ${HASHCRD}select name,PASSWORD HASH,CTIME "CREATION_DATE",PTIME "PASSWORD_LAST_CHANGED" from user\$ where PASSWORD is not null order by 1;
spool off
exit;
EOF
)
fi
# #################################################
# Reporting New Created Objects in the last 24Hours:
# #################################################
NEWOBJCONTRAW=$(${ORACLE_HOME}/bin/sqlplus -S "/ as sysdba" << EOF
set pages 0 feedback off echo off;
select count(*) from dba_objects
where created > sysdate-1
and owner <> 'SYS';
exit;
EOF
)
NEWOBJCONT=`echo ${NEWOBJCONTRAW} | awk '{print $NF}'`
if [ ${NEWOBJCONT} -ge ${NEWOBJCONTTHRESHOLD} ]
then
VALNEWOBJCONT=$(${ORACLE_HOME}/bin/sqlplus -S "/ as sysdba" << EOF
set linesize ${SQLLINESIZE} pages 1000
-- Enable HTML color format:
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD ' ' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
spool ${DB_HEALTHCHK_RPT} app
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT New Created objects [Last 24H]
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} prompt
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
${HASHNONHTML} prompt New Created objects [Last 24H] ...
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
${HASHNONHTML} prompt
col owner for a30
col object_name for a30
col object_type for a19
col created for a20
select object_type,owner,object_name,to_char(created, 'DD-Mon-YYYY HH24:MI:SS') CREATED from dba_objects
where created > sysdate-1
and owner <> 'SYS'
order by owner,object_type;
spool off
exit;
EOF
)
fi
# ###############################################
# Reporting Modified Objects in the last 24Hours:
# ###############################################
MODOBJCONTRAW=$(${ORACLE_HOME}/bin/sqlplus -S "/ as sysdba" << EOF
set pages 0 feedback off echo off;
select count(*) from dba_objects
where LAST_DDL_TIME > sysdate-1
and owner <> 'SYS';
exit;
EOF
)
MODOBJCONT=`echo ${MODOBJCONTRAW} | awk '{print $NF}'`
if [ ${MODOBJCONT} -ge ${MODOBJCONTTHRESHOLD} ]
then
VALMODOBJCONT=$(${ORACLE_HOME}/bin/sqlplus -S "/ as sysdba" << EOF
set linesize ${SQLLINESIZE} pages 1000
-- Enable HTML color format:
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD ' ' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
spool ${DB_HEALTHCHK_RPT} app
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT Modified objects in the Last 24H
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} prompt
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
${HASHNONHTML} prompt Modified objects in the Last 24H ...
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
${HASHNONHTML} prompt
col owner for a30
col object_name for a30
col object_type for a19
col LAST_DDL_TIME for a20
select object_type,owner,object_name,to_char(LAST_DDL_TIME, 'DD-Mon-YYYY HH24:MI:SS') LAST_DDL_TIME from dba_objects
where LAST_DDL_TIME > sysdate-1
and owner <> 'SYS'
order by owner,object_type;
spool off
exit;
EOF
)
fi
# ###############################################
# Checking AUDIT RECORDS ON THE DATABASE:
# ###############################################
# Check if Checking Audit Records is ENABLED:
case ${CHKAUDITRECORDS} in
Y|y|YES|Yes|yes|ON|On|on)
VAL70=$(${ORACLE_HOME}/bin/sqlplus -S "/ as sysdba" << EOF
set pages 0 feedback off echo off;
SELECT (SELECT COUNT(*) FROM dba_audit_trail
where ACTION_NAME not like 'LOGO%' and ACTION_NAME not in ('SELECT','SET ROLE') and timestamp > SYSDATE-1)
+
(SELECT COUNT(*) FROM DBA_AUDIT_SESSION WHERE timestamp > SYSDATE-1 and returncode = 1017)
+
(SELECT COUNT(*) FROM dba_fga_audit_trail WHERE timestamp > SYSDATE-1)
+
(SELECT COUNT(*) FROM dba_objects where created > sysdate-1 and owner <> 'SYS') AUD_REC_COUNT FROM dual;
exit;
EOF
)
VAL80=`echo ${VAL70} | awk '{print $NF}'`
if [ ${VAL80} -ge ${AUDITRECOTHRESHOLD} ]
then
VAL90=$(${ORACLE_HOME}/bin/sqlplus -S "/ as sysdba" << EOF
set linesize ${SQLLINESIZE} pages 1000
-- Enable HTML color format:
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD ' ' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
spool ${LOG_DIR}/audit_records.log
SET TIMING ON
col OS_USERNAME for a20
col EXTENDED_TIMESTAMP for a36
col OWNER for a25
col OBJ_NAME for a25
col OS_USERNAME for a20
col USERNAME for a25
col USERHOST for a35
col ACTION_NAME for a25
col ACTION_OWNER_OBJECT for a55
col TERMINAL for a30
col ACTION_NAME for a20
col TIMESTAMP for a21
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT Failed Login Attempts in the last 24Hours
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} prompt
${HASHNONHTML} prompt
${HASHNONHTML} prompt ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
${HASHNONHTML} prompt Failed Login Attempts in the last 24Hours ...
${HASHNONHTML} prompt ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
${HASHNONHTML} prompt
select to_char (EXTENDED_TIMESTAMP,'DD-MON-YYYY HH24:MI:SS') TIMESTAMP,OS_USERNAME,USERNAME,TERMINAL,USERHOST,ACTION_NAME
from DBA_AUDIT_SESSION
where timestamp > (sysdate -1)
and returncode = 1017
order by 1;
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT Audit records in the last 24Hours AUD$
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} prompt
${HASHNONHTML} prompt
${HASHNONHTML} prompt ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
${HASHNONHTML} prompt Audit records in the last 24Hours AUD$...
${HASHNONHTML} prompt ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
${HASHNONHTML} prompt
select extended_timestamp,OS_USERNAME,USERNAME,USERHOST,ACTION_NAME||' '||OWNER||' . '||OBJ_NAME ACTION_OWNER_OBJECT
from dba_audit_trail
where
timestamp > SYSDATE-1
and ACTION_NAME not like 'LOGO%'
and ACTION_NAME not in ('SELECT','SET ROLE')
-- and USERNAME not in ('CRS_ADMIN','DBSNMP')
-- and OS_USERNAME not in ('workflow')
-- and OBJ_NAME not like '%TMP_%'
-- and OBJ_NAME not like 'WRKDETA%'
-- and OBJ_NAME not in ('PBCATTBL','SETUP','WRKIB','REMWORK')
order by EXTENDED_TIMESTAMP;
${HASHHTML} SET PAGES 0
${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHHTML} PROMPT
${HASHHTML} PROMPT Fine Grained Auditing Data
${HASHHTML} PROMPT |
${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHHTML} set pages 1000
${HASHNONHTML} prompt
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^^^^^^^^^
${HASHNONHTML} prompt Fine Grained Auditing Data ...
${HASHNONHTML} PROMPT ^^^^^^^^^^^^^^^^^^^^^^^^^^
${HASHNONHTML} prompt
col sql_text for a70
col time for a36
col USERHOST for a21
col db_user for a15
select to_char(timestamp,'DD-MM-YYYY HH24:MI:SS') as time,db_user,userhost,sql_text,SQL_BIND
from dba_fga_audit_trail
where
timestamp > SYSDATE-1
-- and policy_name='PAYROLL_TABLE'
order by EXTENDED_TIMESTAMP;
${HASHDORM} ${HASHHTML} SET PAGES 0
${HASHDORM} ${HASHHTML} SET MARKUP HTML OFF SPOOL OFF
${HASHDORM} ${HASHHTML} PROMPT
${HASHDORM} ${HASHHTML} PROMPT Dormant Accounts: [Accounts that did not login in the last ${DORMANT_INACTIVE_DAYS} days]
${HASHDORM} ${HASHHTML} PROMPT |
${HASHDORM} ${HASHHTML} SET WRAP OFF ECHO OFF FEEDBACK OFF MARKUP HTML ON SPOOL ON HEAD '
' TABLE "border='2' bordercolor='#E67E22'" ENTMAP OFF
${HASHDORM} ${HASHHTML} set pages 1000
${HASHDORM} ${HASHNONHTML} prompt
${HASHDORM} ${HASHNONHTML} prompt
${HASHDORM} ${HASHNONHTML} prompt ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
${HASHDORM} ${HASHNONHTML} prompt Dormant Accounts: [Accounts that did not login in the last ${DORMANT_INACTIVE_DAYS} days] ...
${HASHDORM} ${HASHNONHTML} prompt ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
${HASHDORM} ${HASHNONHTML} prompt
${HASHDORM} select userid,max(ntimestamp#) LAST_LOGIN_DATE from aud$ where ntimestamp# < (sysdate - ${DORMANT_INACTIVE_DAYS}) group by userid order by LAST_LOGIN_DATE;
spool off
exit;
EOF
)
cat ${LOG_DIR}/audit_records.log >> ${DB_HEALTHCHK_RPT}
fi
;;
esac
# Remove odd lines from the report:
sed -i 's/^rows will be truncated//g' ${DB_HEALTHCHK_RPT}
export LOGFILE=${DB_HEALTHCHK_RPT}
export MSGSUBJECT="HEALTH CHECK REPORT: For Database [${DB_NAME_UPPER}] on Server [${SRV_NAME}]"
echo ${MSGSUBJECT}
${MAILEXEC} "${MSGSUBJECT}" ${MAIL_LIST} < ${LOGFILE}
(
echo "To: ${EMAIL};"
echo "MIME-Version: 1.0"
echo "Content-Type: text/html;"
echo "Subject: ${MSGSUBJECT}"
cat ${LOGFILE}
) | ${SENDMAIL}
echo "HEALTH CHECK REPORT FOR DATABASE [${DB_NAME_UPPER}] WAS SAVED TO: ${DB_HEALTHCHK_RPT}"
done
echo ""
# #############################
# De-Neutralize login.sql file: [Bug Fix]
# #############################
# If login.sql was renamed during the execution of the script revert it back to its original name:
if [ -f ${USR_ORA_HOME}/login.sql_NeutralizedBy${SCRIPT_NAME} ]
then
mv ${USR_ORA_HOME}/login.sql_NeutralizedBy${SCRIPT_NAME} ${USR_ORA_HOME}/login.sql
fi
# #############
# END OF SCRIPT
# #############
# REPORT BUGS to: mahmmoudadel@hotmail.com
# DOWNLOAD THE LATEST VERSION OF DATABASE ADMINISTRATION BUNDLE FROM:
# http://dba-tips.blogspot.com/2014/02/oracle-database-administration-scripts.html
# DISCLAIMER: THIS SCRIPT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY WARRANTY. IT IS PROVIDED "AS IS".
DBA_BUNDLE6/datafiles.sh 0000740 0152073 0152061 00000015217 13775601525 014754 0 ustar oracle oinstall ###################################################
# Script to show the size of all datafile.
# # # #
# Author: Mahmmoud ADEL # # # # ###
# Created: 24-12-11 # # # # #
#
#
#
###################################################
#############
# Description:
#############
echo
echo "==================================================="
echo "This script Shows the DATAFILES Size on a database."
echo "==================================================="
echo
sleep 1
# #######################################
# Excluded INSTANCES:
# #######################################
# Here you can mention the instances the script will IGNORE and will NOT run against:
# Use pipe "|" as a separator between each instance name.
# e.g. Excluding: -MGMTDB, ASM instances:
EXL_DB="\-MGMTDB|ASM|APX" #Excluded INSTANCES [Will not get reported offline].
#############################
# Listing Available Databases:
#############################
# Count Instance Numbers:
INS_COUNT=$( ps -ef|grep pmon|grep -v grep|egrep -v ${EXL_DB}|wc -l )
# Exit if No DBs are running:
if [ $INS_COUNT -eq 0 ]
then
echo No Database Running !
exit
fi
# If there is ONLY one DB set it as default without prompt for selection:
if [ $INS_COUNT -eq 1 ]
then
export ORACLE_SID=$( ps -ef|grep pmon|grep -v grep|egrep -v ${EXL_DB}|awk '{print $NF}'|sed -e 's/ora_pmon_//g'|grep -v sed|grep -v "s///g" )
# If there is more than one DB ASK the user to select:
elif [ $INS_COUNT -gt 1 ]
then
echo
echo "Select the ORACLE_SID:[Enter the number]"
echo ---------------------
select DB_ID in $( ps -ef|grep pmon|grep -v grep|egrep -v ${EXL_DB}|awk '{print $NF}'|sed -e 's/ora_pmon_//g'|grep -v sed|grep -v "s///g" )
do
integ='^[1-9]+$'
if ! [[ ${REPLY} =~ ${integ} ]] || [ ${REPLY} -gt ${INS_COUNT} ]
then
echo
echo "Error: Not a valid number!"
echo
echo "Enter a valid NUMBER from the displayed list !: i.e. Enter a number from [1 to ${INS_COUNT}]"
echo "-----------------------------------------------"
else
export ORACLE_SID=$DB_ID
echo
printf "`echo "Selected Instance: ["` `echo -e "\033[33;5m${DB_ID}\033[0m"` `echo "]"`\n"
echo
break
fi
done
fi
# Exit if the user selected a Non Listed Number:
if [ -z "${ORACLE_SID}" ]
then
echo "You've Entered An INVALID ORACLE_SID"
exit
fi
# #########################
# Getting ORACLE_HOME
# #########################
ORA_USER=`ps -ef|grep ${ORACLE_SID}|grep pmon|grep -v grep|egrep -v ${EXL_DB}|awk '{print $1}'|tail -1`
USR_ORA_HOME=`grep ${ORA_USER} /etc/passwd| cut -f6 -d ':'|tail -1`
# SETTING ORATAB:
if [ -f /etc/oratab ]
then
ORATAB=/etc/oratab
export ORATAB
## If OS is Solaris:
elif [ -f /var/opt/oracle/oratab ]
then
ORATAB=/var/opt/oracle/oratab
export ORATAB
fi
# ATTEMPT1: Get ORACLE_HOME using pwdx command:
export PGREP=`which pgrep`
export PWDX=`which pwdx`
if [[ -x ${PGREP} ]] && [[ -x ${PWDX} ]]
then
PMON_PID=`pgrep -lf _pmon_${ORACLE_SID}|awk '{print $1}'`
export PMON_PID
ORACLE_HOME=`pwdx ${PMON_PID}|awk '{print $NF}'|sed -e 's/\/dbs//g'`
export ORACLE_HOME
fi
# ATTEMPT2: If ORACLE_HOME not found get it from oratab file:
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
## If OS is Linux:
if [ -f /etc/oratab ]
then
ORATAB=/etc/oratab
ORACLE_HOME=`grep -v '^\#' $ORATAB | grep -v '^$'| grep -i "^${ORACLE_SID}:" | perl -lpe'$_ = reverse' | cut -f3 | perl -lpe'$_ = reverse' |cut -f2 -d':'`
export ORACLE_HOME
## If OS is Solaris:
elif [ -f /var/opt/oracle/oratab ]
then
ORATAB=/var/opt/oracle/oratab
ORACLE_HOME=`grep -v '^\#' $ORATAB | grep -v '^$'| grep -i "^${ORACLE_SID}:" | perl -lpe'$_ = reverse' | cut -f3 | perl -lpe'$_ = reverse' |cut -f2 -d':'`
export ORACLE_HOME
fi
#echo "ORACLE_HOME from oratab is ${ORACLE_HOME}"
fi
# ATTEMPT3: If ORACLE_HOME is still not found, search for the environment variable: [Less accurate]
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
ORACLE_HOME=`env|grep -i ORACLE_HOME|sed -e 's/ORACLE_HOME=//g'`
export ORACLE_HOME
#echo "ORACLE_HOME from environment is ${ORACLE_HOME}"
fi
# ATTEMPT4: If ORACLE_HOME is not found in the environment search user's profile: [Less accurate]
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
ORACLE_HOME=`grep -h 'ORACLE_HOME=\/' $USR_ORA_HOME/.bash_profile $USR_ORA_HOME/.*profile | perl -lpe'$_ = reverse' |cut -f1 -d'=' | perl -lpe'$_ = reverse'|tail -1`
export ORACLE_HOME
#echo "ORACLE_HOME from User Profile is ${ORACLE_HOME}"
fi
# ATTEMPT5: If ORACLE_HOME is still not found, search for orapipe: [Least accurate]
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
ORACLE_HOME=`locate -i orapipe|head -1|sed -e 's/\/bin\/orapipe//g'`
export ORACLE_HOME
#echo "ORACLE_HOME from orapipe search is ${ORACLE_HOME}"
fi
# TERMINATE: If all above attempts failed to get ORACLE_HOME location, EXIT the script:
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
echo "Please export ORACLE_HOME variable in your .bash_profile file under oracle user home directory in order to get this script to run properly"
echo "e.g."
echo "export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1"
exit
fi
export LD_LIBRARY_PATH=${ORACLE_HOME}/lib
##########################################
# Exit if the user is not the Oracle Owner:
##########################################
CURR_USER=`whoami`
if [ ${ORA_USER} != ${CURR_USER} ]; then
echo ""
echo "You're Running This Sctipt with User: \"${CURR_USER}\" !!!"
echo "Please Run This Script With The Right OS User: \"${ORA_USER}\""
echo "Script Terminated!"
exit
fi
#######################
# Checking Datafiles:
#######################
$ORACLE_HOME/bin/sqlplus -S '/ as sysdba' <.
# DISCLAIMER: THIS SCRIPT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY WARRANTY. IT IS PROVIDED "AS IS".
# DOWNLOAD THE LATEST VERSION OF DATABASE ADMINISTRATION BUNDLE FROM: http://dba-tips.blogspot.com/2014/02/oracle-database-administration-scripts.html
DBA_BUNDLE6/lock_user.sh 0000740 0152073 0152061 00000020020 13775601710 014766 0 ustar oracle oinstall # #################################################
# Script to unlock locked users # # #
# Author: Mahmmoud ADEL # # # # ###
# Created: 24-12-11 # # # # #
# Modified: 31-12-13
# Customized the script to run on
# various environments.
# 16-09-14 Removed User Confirmation.
#
#
# #################################################
SCRIPT_NAME="lock_user"
# ###########
# Description:
# ###########
echo
echo "================================="
echo "This script LOCKS database users."
echo "================================="
echo
sleep 1
# #######################################
# Excluded INSTANCES:
# #######################################
# Here you can mention the instances the script will IGNORE and will NOT run against:
# Use pipe "|" as a separator between each instance name.
# e.g. Excluding: -MGMTDB, ASM instances:
EXL_DB="\-MGMTDB|ASM|APX" #Excluded INSTANCES [Will not get reported offline].
# ###########################
# Listing Available Databases:
# ###########################
# Count Instance Numbers:
INS_COUNT=$( ps -ef|grep pmon|grep -v grep|egrep -v ${EXL_DB}|wc -l )
# Exit if No DBs are running:
if [ $INS_COUNT -eq 0 ]
then
echo No Database Running !
exit
fi
# If there is ONLY one DB set it as default without prompt for selection:
if [ $INS_COUNT -eq 1 ]
then
export ORACLE_SID=$( ps -ef|grep pmon|grep -v grep|grep -v ASM|awk '{print $NF}'|sed -e 's/ora_pmon_//g'|grep -v sed|grep -v "s///g" )
# If there is more than one DB ASK the user to select:
elif [ $INS_COUNT -gt 1 ]
then
echo
echo "Select the ORACLE_SID:[Enter the number]"
echo ---------------------
select DB_ID in $( ps -ef|grep pmon|grep -v grep|grep -v ASM|awk '{print $NF}'|sed -e 's/ora_pmon_//g'|grep -v sed|grep -v "s///g" )
do
integ='^[1-9]+$'
if ! [[ ${REPLY} =~ ${integ} ]] || [ ${REPLY} -gt ${INS_COUNT} ]
then
echo
echo "Error: Not a valid number!"
echo
echo "Enter a valid NUMBER from the displayed list !: i.e. Enter a number from [1 to ${INS_COUNT}]"
echo "-----------------------------------------------"
else
export ORACLE_SID=$DB_ID
echo
printf "`echo "Selected Instance: ["` `echo -e "\033[33;5m${DB_ID}\033[0m"` `echo "]"`\n"
echo
break
fi
done
fi
# Exit if the user selected a Non Listed Number:
if [ -z "${ORACLE_SID}" ]
then
echo "You've Entered An INVALID ORACLE_SID"
exit
fi
# #########################
# Getting ORACLE_HOME
# #########################
ORA_USER=`ps -ef|grep ${ORACLE_SID}|grep pmon|grep -v grep|grep -v ASM|grep -v "\-MGMTDB"|awk '{print $1}'|tail -1`
USR_ORA_HOME=`grep ${ORA_USER} /etc/passwd| cut -f6 -d ':'|tail -1`
# SETTING ORATAB:
if [ -f /etc/oratab ]
then
ORATAB=/etc/oratab
export ORATAB
## If OS is Solaris:
elif [ -f /var/opt/oracle/oratab ]
then
ORATAB=/var/opt/oracle/oratab
export ORATAB
fi
# ATTEMPT1: Get ORACLE_HOME using pwdx command:
export PGREP=`which pgrep`
export PWDX=`which pwdx`
if [[ -x ${PGREP} ]] && [[ -x ${PWDX} ]]
then
PMON_PID=`pgrep -lf _pmon_${ORACLE_SID}|awk '{print $1}'`
export PMON_PID
ORACLE_HOME=`pwdx ${PMON_PID}|awk '{print $NF}'|sed -e 's/\/dbs//g'`
export ORACLE_HOME
fi
# ATTEMPT2: If ORACLE_HOME not found get it from oratab file:
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
## If OS is Linux:
if [ -f /etc/oratab ]
then
ORATAB=/etc/oratab
ORACLE_HOME=`grep -v '^\#' $ORATAB | grep -v '^$'| grep -i "^${ORACLE_SID}:" | perl -lpe'$_ = reverse' | cut -f3 | perl -lpe'$_ = reverse' |cut -f2 -d':'`
export ORACLE_HOME
## If OS is Solaris:
elif [ -f /var/opt/oracle/oratab ]
then
ORATAB=/var/opt/oracle/oratab
ORACLE_HOME=`grep -v '^\#' $ORATAB | grep -v '^$'| grep -i "^${ORACLE_SID}:" | perl -lpe'$_ = reverse' | cut -f3 | perl -lpe'$_ = reverse' |cut -f2 -d':'`
export ORACLE_HOME
fi
#echo "ORACLE_HOME from oratab is ${ORACLE_HOME}"
fi
# ATTEMPT3: If ORACLE_HOME is still not found, search for the environment variable: [Less accurate]
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
ORACLE_HOME=`env|grep -i ORACLE_HOME|sed -e 's/ORACLE_HOME=//g'`
export ORACLE_HOME
#echo "ORACLE_HOME from environment is ${ORACLE_HOME}"
fi
# ATTEMPT4: If ORACLE_HOME is not found in the environment search user's profile: [Less accurate]
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
ORACLE_HOME=`grep -h 'ORACLE_HOME=\/' $USR_ORA_HOME/.bash_profile $USR_ORA_HOME/.*profile | perl -lpe'$_ = reverse' |cut -f1 -d'=' | perl -lpe'$_ = reverse'|tail -1`
export ORACLE_HOME
#echo "ORACLE_HOME from User Profile is ${ORACLE_HOME}"
fi
# ATTEMPT5: If ORACLE_HOME is still not found, search for orapipe: [Least accurate]
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
ORACLE_HOME=`locate -i orapipe|head -1|sed -e 's/\/bin\/orapipe//g'`
export ORACLE_HOME
#echo "ORACLE_HOME from orapipe search is ${ORACLE_HOME}"
fi
# TERMINATE: If all above attempts failed to get ORACLE_HOME location, EXIT the script:
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
echo "Please export ORACLE_HOME variable in your .bash_profile file under oracle user home directory in order to get this script to run properly"
echo "e.g."
echo "export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1"
exit
fi
export LD_LIBRARY_PATH=${ORACLE_HOME}/lib
# ########################################
# Exit if the user is not the Oracle Owner:
# ########################################
CURR_USER=`whoami`
if [ ${ORA_USER} != ${CURR_USER} ]; then
echo ""
echo "You're Running This Sctipt with User: \"${CURR_USER}\" !!!"
echo "Please Run This Script With The Right OS User: \"${ORA_USER}\""
echo "Script Terminated!"
exit
fi
# #############################
# SQLPLUS: Lock An Oracle User:
# #############################
# Variables
echo
echo "Please enter the USERID:"
echo "======================="
while read USERNAME2
do
VAL11=$(${ORACLE_HOME}/bin/sqlplus -s '/ as sysdba' << EOF
SELECT COUNT(*) FROM DBA_USERS WHERE USERNAME=upper('$USERNAME2');
EOF
)
VAL22=`echo $VAL11| awk '{print $NF}'`
case ${VAL22} in
# If the provided value match an exist username in the DB:
1)
${ORACLE_HOME}/bin/sqlplus -s '/ as sysdba' << EOF
SELECT USERNAME,ACCOUNT_STATUS FROM DBA_USERS WHERE USERNAME=upper('$USERNAME2');
PROMPT
PROMPT Locking user [${USERNAME2}] ...
PROMPT
EOF
VAL1=$(${ORACLE_HOME}/bin/sqlplus -s '/ as sysdba' << EOF
ALTER user $USERNAME2 ACCOUNT LOCK;
EOF
)
VAL2=`echo $VAL1| grep "User altered"`
if [ -z "${VAL2}" ]
then
echo "Failed to lock User \"${USERNAME2}\" !"
echo
exit
else
echo
echo User ${USERNAME2} locked Successfully.
echo
fi; break;;
# If no value provided or the value doesn't match any user in the DB try to search for matching:
*) echo; echo "INFO: USER [${USERNAME2}] IS NOT EXIST ON DATABASE [$ORACLE_SID] !"
echo; echo "Searching ..."; sleep 1
${ORACLE_HOME}/bin/sqlplus -s '/ as sysdba' << EOF
set linesize 143
set pagesize 1000
set feedback off
set trim on
set echo off
col USERNAME for a30
col account_status for a23
select username,account_status,profile,LOCK_DATE,EXPIRY_DATE from dba_users where username like upper ('%$USERNAME2%');
EOF
echo; echo "Please Enter the FULL USERID:"
echo "=============================" ;;
esac
done
# #############
# END OF SCRIPT
# #############
# REPORT BUGS to: mahmmoudadel@hotmail.com
# DISCLAIMER: THIS SCRIPT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY WARRANTY. IT IS PROVIDED "AS IS".
# DOWNLOAD THE LATEST VERSION OF DATABASE ADMINISTRATION BUNDLE FROM: http://dba-tips.blogspot.com/2014/02/oracle-database-administration-scripts.html
DBA_BUNDLE6/kill_long_running_queries.sh 0000740 0152073 0152061 00000025233 13775602246 020267 0 ustar oracle oinstall # #######################################################################
# Kill queries running for more than N hours based on specific criteria.
# #######################################################################
VER="[1.0]"
# # # #
# Author: Mahmmoud ADEL # # # # ###
# Created: 11-01-18 # # # # #
#
#
#
#
# #######################################################################
# #####################
# Environment Variables: [ORACLE_SID must be set by the user in case multiple instances running]
# #####################
export ORACLE_SID=
export SCRIPT_NAME="kill_long_running_queries"
export SRV_NAME=`uname -n`
#export LNXVER=`cat /etc/redhat-release | grep -o '[0-9]'|head -1`
export LOGFILE=/tmp/${SCRIPT_NAME}.log
export TERMINATOR_SCRIPT=/tmp/KILL_LONG_QUERIES.sql
# Email Recipients:
# ################
MAIL_LIST="youremail@yourcompany.com"
export MAIL_LIST
# #######################################
# SCRIPT OPTIONS:
# #######################################
# #################
# KILLING Criteria:
# #################
# Module Name: [Put "," between each module name and keep each module name between single quote]
# e.g. export MODULE_NAME="'SQL Developer','Toad'"
export MODULE_NAME="'SQL Developer'"
# Duration [In hours and its fraction] when exceeded the query will get killed:
# e.g. To kill the queries that exceed 3 hours and 30 minutes export DURATION="3.5"
export DURATION="2.5"
# Report Only Semaphore: [The script will NOT KILL any query if it set to Y but will report them to the user]
# Y to report long sessions by email without killing them.
# N to Kill long sessions and report them after killing to the user. [Default]
export REPORT_ONLY="N"
case ${REPORT_ONLY} in
Y|y|yes|Yes|YES) export HASH_SCRIPT="--";export REPORT_ONLY_MESSAGE="PROMPT REPORT_ONLY Semaphore is set to Y, No Killing will happen";;
*) export HASH_SCRIPT="";export REPORT_ONLY_MESSAGE="";;
esac
# ####################################################################
# Check if ORACLE_SID & MAIL_LIST variables is already set by the user:
# ####################################################################
export EXL_DB="\-MGMTDB|ASM|APX" # Instances to not be considered when running the script
INS_COUNT=$( ps -ef|grep pmon|grep -v grep|egrep -v ${EXL_DB}|wc -l )
case ${ORACLE_SID} in "")
# Exit if No DBs are running:
if [ ${INS_COUNT} -eq 0 ]
then
echo No Database Running !
exit
fi
# If there is ONLY one DB make it the default ORACLE_SID:
if [ ${INS_COUNT} -eq 1 ]
then
export ORACLE_SID=$( ps -ef|grep pmon|grep -v grep|egrep -v ${EXL_DB}|awk '{print $NF}'|sed -e 's/ora_pmon_//g'|grep -v sed|grep -v "s///g" )
# If there is more than one DB ASK the user to set the ORACLE_SID manually:
elif [ ${INS_COUNT} -gt 1 ]
then
echo
echo
echo "*****"
echo "ERROR! You have to manually set ORACLE_SID to one of the following instances in the 'Environment Variables' Section!"
echo "*****"
ps -ef|grep pmon|grep -v grep|egrep -v ${EXL_DB}|awk '{print $NF}'|sed -e 's/ora_pmon_//g'|grep -v sed|grep -v "s///g"
echo
echo "Script Terminated !"
echo
exit
fi
;;
esac
# #########################
# Getting ORACLE_HOME
# #########################
ORA_USER=`ps -ef|grep ${ORACLE_SID}|grep pmon|grep -v grep|egrep -v ${EXL_DB}|grep -v "\-MGMTDB"|awk '{print $1}'|tail -1`
USR_ORA_HOME=`grep ${ORA_USER} /etc/passwd| cut -f6 -d ':'|tail -1`
# SETTING ORATAB:
if [ -f /etc/oratab ]
then
ORATAB=/etc/oratab
export ORATAB
## If OS is Solaris:
elif [ -f /var/opt/oracle/oratab ]
then
ORATAB=/var/opt/oracle/oratab
export ORATAB
fi
# ATTEMPT1: Get ORACLE_HOME using pwdx command:
export PGREP=`which pgrep`
export PWDX=`which pwdx`
if [[ -x ${PGREP} ]] && [[ -x ${PWDX} ]]
then
PMON_PID=`pgrep -lf _pmon_${ORACLE_SID}|awk '{print $1}'`
export PMON_PID
ORACLE_HOME=`pwdx ${PMON_PID}|awk '{print $NF}'|sed -e 's/\/dbs//g'`
export ORACLE_HOME
fi
# ATTEMPT2: If ORACLE_HOME not found get it from oratab file:
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
## If OS is Linux:
if [ -f /etc/oratab ]
then
ORATAB=/etc/oratab
ORACLE_HOME=`grep -v '^\#' $ORATAB | grep -v '^$'| grep -i "^${ORACLE_SID}:" | perl -lpe'$_ = reverse' | cut -f3 | perl -lpe'$_ = reverse' |cut -f2 -d':'`
export ORACLE_HOME
## If OS is Solaris:
elif [ -f /var/opt/oracle/oratab ]
then
ORATAB=/var/opt/oracle/oratab
ORACLE_HOME=`grep -v '^\#' $ORATAB | grep -v '^$'| grep -i "^${ORACLE_SID}:" | perl -lpe'$_ = reverse' | cut -f3 | perl -lpe'$_ = reverse' |cut -f2 -d':'`
export ORACLE_HOME
fi
#echo "ORACLE_HOME from oratab is ${ORACLE_HOME}"
fi
# ATTEMPT3: If ORACLE_HOME is still not found, search for the environment variable: [Less accurate]
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
ORACLE_HOME=`env|grep -i ORACLE_HOME|sed -e 's/ORACLE_HOME=//g'`
export ORACLE_HOME
#echo "ORACLE_HOME from environment is ${ORACLE_HOME}"
fi
# ATTEMPT4: If ORACLE_HOME is not found in the environment search user's profile: [Less accurate]
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
ORACLE_HOME=`grep -h 'ORACLE_HOME=\/' $USR_ORA_HOME/.bash_profile $USR_ORA_HOME/.*profile | perl -lpe'$_ = reverse' |cut -f1 -d'=' | perl -lpe'$_ = reverse'|tail -1`
export ORACLE_HOME
#echo "ORACLE_HOME from User Profile is ${ORACLE_HOME}"
fi
# ATTEMPT5: If ORACLE_HOME is still not found, search for orapipe: [Least accurate]
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
ORACLE_HOME=`locate -i orapipe|head -1|sed -e 's/\/bin\/orapipe//g'`
export ORACLE_HOME
#echo "ORACLE_HOME from orapipe search is ${ORACLE_HOME}"
fi
# TERMINATE: If all above attempts failed to get ORACLE_HOME location, EXIT the script:
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
echo "Please export ORACLE_HOME variable in your .bash_profile file under oracle user home directory in order to get this script to run properly"
echo "e.g."
echo "export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1"
exit
fi
export LD_LIBRARY_PATH=${ORACLE_HOME}/lib
# Neutralize login.sql file:
# #########################
# Existance of login.sql file under current working directory eliminates many functions during the execution of this script:
if [ -f ./login.sql ]
then
mv ./login.sql ./login.sql_NeutralizedBy${SCRIPT_NAME}
fi
# ###########
# SCRIPT BODY:
# ###########
# Script Description:
echo ""
echo "This Script Kills the sessions running a query for more than ${DURATION} hours and connecting from ${MODULE_NAME} ..."
sleep 1
# Flush the logfile:
cat /dev/null > ${LOGFILE}
# CHECKING RUNNING SESSIONS:
SESSIONS_COUNT_RAW=$(${ORACLE_HOME}/bin/sqlplus -S "/ as sysdba" < 60*60*${DURATION}
and status = 'ACTIVE'
;
exit;
EOF
)
SESSIONS_COUNT=`echo ${SESSIONS_COUNT_RAW}|perl -lpe'$_ = reverse' |awk '{print $1}'|perl -lpe'$_ = reverse'|cut -f1 -d '.'`
# KILLING LONG RUNNING SESSIONS IF EXIST:
# ######################################
if [ ${SESSIONS_COUNT} -gt 0 ]
then
echo "Found ${SESSIONS_COUNT} Candidate sessions to be killed!"
KILL_SESSION_RAW=$(${ORACLE_HOME}/bin/sqlplus -S "/ as sysdba" < 60*60*${DURATION}
and status = 'ACTIVE'
;
spool off
-- Kill SQL Script creation:
set pages 0 feedback off echo off
spool ${TERMINATOR_SCRIPT}
select 'ALTER SYSTEM DISCONNECT SESSION '''||sid||','||serial#||''' IMMEDIATE;'
from V\$SESSION
where
MODULE in (${MODULE_NAME})
and last_call_et > 60*60*${DURATION}
and status = 'ACTIVE'
;
spool off
-- Run the Terminator Script to kill the sessions:
set pages 1000 feedback on echo on
spool ${LOGFILE} APPEND
PROMPT
PROMPT Running The Terminator Script:
PROMPT *****************************
${REPORT_ONLY_MESSAGE}
${HASH_SCRIPT}START ${TERMINATOR_SCRIPT}
spool off
exit;
EOF
)
sleep 10
CURRENT_LONG_SESS_RAW=$(${ORACLE_HOME}/bin/sqlplus -S "/ as sysdba" < 60*60*${DURATION}
and status = 'ACTIVE'
;
spool off
exit;
EOF
)
# EMAIL Notification with the killed session:
case ${MAIL_LIST} in
"youremail@yourcompany.com");;
*)
/bin/mail -s "Info: Long Running QUERY KILLED on [${ORACLE_SID}]" ${MAIL_LIST} < ${LOGFILE};;
esac
else
echo ""
echo "Hooray! No Candidate Sessions were found based on the Killing Criteria."
echo ""
fi
# De-Neutralize login.sql file:
# ############################
# If login.sql was renamed during the execution of the script revert it back to its original name:
if [ -f ./login.sql_NeutralizedBy${SCRIPT_NAME} ]
then
mv ./login.sql_NeutralizedBy${SCRIPT_NAME} ./login.sql
fi
# #############
# END OF SCRIPT
# #############
# REPORT BUGS to: mahmmoudadel@hotmail.com
# DOWNLOAD THE LATEST VERSION OF DATABASE ADMINISTRATION BUNDLE FROM:
# http://dba-tips.blogspot.com/2014/02/oracle-database-administration-scripts.html
# DISCLAIMER: THIS SCRIPT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY WARRANTY. IT IS PROVIDED "AS IS".
DBA_BUNDLE6/.HA_SERVICES_STATUS.sh 0000740 0152073 0152061 00000000736 14115055307 015762 0 ustar oracle oinstall /u01/app/grid/product/12.2.0/grid/bin/crsctl status res |grep -v "^$"|awk -F "=" 'BEGIN {print " "} {printf("%s",NR%4 ? $2"|" : $2"\n")}'|sed -e 's/ *, /,/g' -e 's/, /,/g'|awk -F "|" 'BEGIN { printf "%-50s%-50s\n","Resource Name","STATUS";printf "%-50s%-50s\n", "-------------------------------------","----------------------"; }{ split ($3,trg,",") split ($4,st,",")}{for (i in trg) {printf "%-50s%-50s\n",$1,st[i]}}'|egrep -v "ora.proxy_advm|ora.asmgroup|ora.diskmon|ora.ons"
DBA_BUNDLE6/user_details.sh 0000740 0152073 0152061 00000026621 13775601601 015477 0 ustar oracle oinstall ###################################################
# This script show the user details (Creation Stmt)
# # # #
# Author: Mahmmoud ADEL # # # # ###
# Created: 24-09-11 # # # # #
# Modified: 31-12-13
# Customized the script to run on
# various environments.
# 19-02-14
# Added USER's OBJECT COUNT.
# 16-09-14 Add Search Feature.
###################################################
# ###########
# Description:
# ###########
echo
echo "========================================================"
echo "This script generates the CREATION STATEMENT for a USER."
echo "========================================================"
echo
sleep 1
# #######################################
# Excluded INSTANCES:
# #######################################
# Here you can mention the instances the script will IGNORE and will NOT run against:
# Use pipe "|" as a separator between each instance name.
# e.g. Excluding: -MGMTDB, ASM instances:
EXL_DB="\-MGMTDB|ASM|APX" #Excluded INSTANCES [Will not get reported offline].
# ##############################
# SCRIPT ENGINE STARTS FROM HERE ............................................
# ##############################
# ###########################
# Listing Available Databases:
# ###########################
# Count Instance Numbers:
INS_COUNT=$( ps -ef|grep pmon|grep -v grep|egrep -v ${EXL_DB}|wc -l )
# Exit if No DBs are running:
if [ $INS_COUNT -eq 0 ]
then
echo No Database Running !
exit
fi
# If there is ONLY one DB set it as default without prompt for selection:
if [ $INS_COUNT -eq 1 ]
then
export ORACLE_SID=$( ps -ef|grep pmon|grep -v grep|egrep -v ${EXL_DB}|awk '{print $NF}'|sed -e 's/ora_pmon_//g'|grep -v sed|grep -v "s///g" )
# If there is more than one DB ASK the user to select:
elif [ $INS_COUNT -gt 1 ]
then
echo
echo "Select the ORACLE_SID:[Enter the number]"
echo ---------------------
select DB_ID in $( ps -ef|grep pmon|grep -v grep|egrep -v ${EXL_DB}|awk '{print $NF}'|sed -e 's/ora_pmon_//g'|grep -v sed|grep -v "s///g" )
do
integ='^[1-9]+$'
if ! [[ ${REPLY} =~ ${integ} ]] || [ ${REPLY} -gt ${INS_COUNT} ]
then
echo
echo "Error: Not a valid number!"
echo
echo "Enter a valid NUMBER from the displayed list !: i.e. Enter a number from [1 to ${INS_COUNT}]"
echo "-----------------------------------------------"
else
export ORACLE_SID=$DB_ID
echo
printf "`echo "Selected Instance: ["` `echo -e "\033[33;5m${DB_ID}\033[0m"` `echo "]"`\n"
echo
break
fi
done
fi
# Exit if the user selected a Non Listed Number:
if [ -z "${ORACLE_SID}" ]
then
echo "You've Entered An INVALID ORACLE_SID"
exit
fi
# #########################
# Getting ORACLE_HOME
# #########################
ORA_USER=`ps -ef|grep ${ORACLE_SID}|grep pmon|grep -v grep|egrep -v ${EXL_DB}|awk '{print $1}'|tail -1`
USR_ORA_HOME=`grep ${ORA_USER} /etc/passwd| cut -f6 -d ':'|tail -1`
# SETTING ORATAB:
if [ -f /etc/oratab ]
then
ORATAB=/etc/oratab
export ORATAB
## If OS is Solaris:
elif [ -f /var/opt/oracle/oratab ]
then
ORATAB=/var/opt/oracle/oratab
export ORATAB
fi
# ATTEMPT1: Get ORACLE_HOME using pwdx command:
export PGREP=`which pgrep`
export PWDX=`which pwdx`
if [[ -x ${PGREP} ]] && [[ -x ${PWDX} ]]
then
PMON_PID=`pgrep -lf _pmon_${ORACLE_SID}|awk '{print $1}'`
export PMON_PID
ORACLE_HOME=`pwdx ${PMON_PID}|awk '{print $NF}'|sed -e 's/\/dbs//g'`
export ORACLE_HOME
fi
# ATTEMPT2: If ORACLE_HOME not found get it from oratab file:
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
## If OS is Linux:
if [ -f /etc/oratab ]
then
ORATAB=/etc/oratab
ORACLE_HOME=`grep -v '^\#' $ORATAB | grep -v '^$'| grep -i "^${ORACLE_SID}:" | perl -lpe'$_ = reverse' | cut -f3 | perl -lpe'$_ = reverse' |cut -f2 -d':'`
export ORACLE_HOME
## If OS is Solaris:
elif [ -f /var/opt/oracle/oratab ]
then
ORATAB=/var/opt/oracle/oratab
ORACLE_HOME=`grep -v '^\#' $ORATAB | grep -v '^$'| grep -i "^${ORACLE_SID}:" | perl -lpe'$_ = reverse' | cut -f3 | perl -lpe'$_ = reverse' |cut -f2 -d':'`
export ORACLE_HOME
fi
#echo "ORACLE_HOME from oratab is ${ORACLE_HOME}"
fi
# ATTEMPT3: If ORACLE_HOME is still not found, search for the environment variable: [Less accurate]
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
ORACLE_HOME=`env|grep -i ORACLE_HOME|sed -e 's/ORACLE_HOME=//g'`
export ORACLE_HOME
#echo "ORACLE_HOME from environment is ${ORACLE_HOME}"
fi
# ATTEMPT4: If ORACLE_HOME is not found in the environment search user's profile: [Less accurate]
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
ORACLE_HOME=`grep -h 'ORACLE_HOME=\/' $USR_ORA_HOME/.bash_profile $USR_ORA_HOME/.*profile | perl -lpe'$_ = reverse' |cut -f1 -d'=' | perl -lpe'$_ = reverse'|tail -1`
export ORACLE_HOME
#echo "ORACLE_HOME from User Profile is ${ORACLE_HOME}"
fi
# ATTEMPT5: If ORACLE_HOME is still not found, search for orapipe: [Least accurate]
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
ORACLE_HOME=`locate -i orapipe|head -1|sed -e 's/\/bin\/orapipe//g'`
export ORACLE_HOME
#echo "ORACLE_HOME from orapipe search is ${ORACLE_HOME}"
fi
# TERMINATE: If all above attempts failed to get ORACLE_HOME location, EXIT the script:
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
echo "Please export ORACLE_HOME variable in your .bash_profile file under oracle user home directory in order to get this script to run properly"
echo "e.g."
echo "export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1"
exit
fi
export LD_LIBRARY_PATH=${ORACLE_HOME}/lib
# ########################################
# Exit if the user is not the Oracle Owner:
# ########################################
CURR_USER=`whoami`
if [ ${ORA_USER} != ${CURR_USER} ]; then
echo ""
echo "You're Running This Sctipt with User: \"${CURR_USER}\" !!!"
echo "Please Run This Script With The Right OS User: \"${ORA_USER}\""
echo "Script Terminated!"
exit
fi
# ################################################################
# SQLPLUS: Get the creation statement of a USER plus extra details:
# ################################################################
# Variables
echo
echo Please enter the Username:
echo "========================="
while read USERNAME
do
case ${USERNAME} in
"")echo
echo "Enter the Username:"
echo "==================";;
public|PUBLIC|Public)
SPOOL_FILE="${USR_ORA_HOME}"/"${USERNAME}"_creation_stmt.log
${ORACLE_HOME}/bin/sqlplus -s '/ as sysdba' << EOF
set pages 0 lines 200
set echo off heading off feedback off
spool '$SPOOL_FILE'
select 'GRANT '||GRANTED_ROLE||' TO '||GRANTEE||';' from dba_role_privs where grantee= 'PUBLIC'
UNION
select 'GRANT '||PRIVILEGE||' TO '||GRANTEE||';' from dba_sys_privs where grantee= 'PUBLIC'
UNION
select 'GRANT '||PRIVILEGE||' ON '||OWNER||'.'||TABLE_NAME||' TO '||GRANTEE||';'
from DBA_TAB_PRIVS where GRANTEE='PUBLIC' and OWNER not in ('SYS','SYSTEM','WMSYS','XDB','DBSNMP','OLAPSYS','ORDSYS');
spool off
EOF
if [ -f "${SPOOL_FILE}" ]
then
echo;echo "The Creation Statement has been spooled in: ${SPOOL_FILE}"
echo
fi
exit;break ;;
*)
VAL11=$(${ORACLE_HOME}/bin/sqlplus -s '/ as sysdba' << EOF
SELECT COUNT(*) FROM DBA_USERS WHERE USERNAME=upper('$USERNAME');
EOF
)
VAL22=`echo $VAL11| awk '{print $NF}'`
case ${VAL22} in
0) echo;echo "INFO: USER [${USERNAME}] IS NOT EXIST ON DATABASE [$ORACLE_SID] !"
echo; echo "Searching..."; sleep 1
${ORACLE_HOME}/bin/sqlplus -s '/ as sysdba' << EOF
set pagesize 1000 lines 200
set feedback off
set trim on
set echo off
col USERNAME for a30
col account_status for a23
select username,account_status,profile from dba_users where username like upper ('%$USERNAME%');
EOF
echo; echo "Please Enter the FULL USERID:";echo "=============================" ;;
*) break;;
esac
esac
done
SPOOL_FILE="${USR_ORA_HOME}"/"${USERNAME}"_creation_stmt.log
${ORACLE_HOME}/bin/sqlplus -s '/ as sysdba' << EOF
set pages 0 lines 200
set echo off heading off feedback off
spool '$SPOOL_FILE'
SELECT 'CREATE USER ' || u.username ||' IDENTIFIED ' ||' BY VALUES ''' || c.password || ''' DEFAULT TABLESPACE ' || u.default_tablespace ||' TEMPORARY TABLESPACE ' || u.temporary_tablespace ||' PROFILE ' || u.profile || case when account_status= 'OPEN' then ';' else ' Account LOCK;' end "--Creation Statement"
FROM dba_users u,user$ c where u.username=c.name and u.username=upper('$USERNAME')
UNION
select 'GRANT '||GRANTED_ROLE||' TO '||GRANTEE|| case when ADMIN_OPTION='YES' then ' WITH ADMIN OPTION;' else ';' end "Granted Roles"
from dba_role_privs where grantee= upper('$USERNAME')
UNION
select 'GRANT '||PRIVILEGE||' TO '||GRANTEE|| case when ADMIN_OPTION='YES' then ' WITH ADMIN OPTION;' else ';' end "Granted System Privileges"
from dba_sys_privs where grantee= upper('$USERNAME')
UNION
select 'GRANT '||PRIVILEGE||' ON '||OWNER||'.'||TABLE_NAME||' TO '||GRANTEE||case when GRANTABLE='YES' then ' WITH GRANT OPTION;' else ';' end "Granted Object Privileges"
from DBA_TAB_PRIVS where GRANTEE=upper('$USERNAME');
spool off
set heading on pages 1000
col USERNAME for a25
col PASSWORD for a25
col account_status for a23
col PROFILE for a15
col DEFAULT_TABLESPACE for a20
col TEMPORARY_TABLESPACE for a20
PROMPT
SELECT A.USERNAME,B.PASSWORD,A.ACCOUNT_STATUS,A.PROFILE,A.DEFAULT_TABLESPACE,A.TEMPORARY_TABLESPACE FROM DBA_USERS A, USER$ B WHERE A.USER_ID=B.USER# AND USERNAME=UPPER('$USERNAME');
PROMPT
PROMPT USER's OBJECT COUNT:
PROMPT --------------------
select USERNAME,
count(decode(o.TYPE#, 2,o.OBJ#,'')) Tables,
count(decode(o.TYPE#, 1,o.OBJ#,'')) Indexes,
count(decode(o.TYPE#, 5,o.OBJ#,'')) Syns,
count(decode(o.TYPE#, 4,o.OBJ#,'')) Views,
count(decode(o.TYPE#, 6,o.OBJ#,'')) Seqs,
count(decode(o.TYPE#, 7,o.OBJ#,'')) Procs,
count(decode(o.TYPE#, 8,o.OBJ#,'')) Funcs,
count(decode(o.TYPE#, 9,o.OBJ#,'')) Pkgs,
count(decode(o.TYPE#,12,o.OBJ#,'')) Trigs,
count(decode(o.TYPE#,10,o.OBJ#,'')) Deps
from obj$ o,
dba_users u
where u.USER_ID = o.OWNER# (+) and u.USERNAME=upper('$USERNAME')
group by USERNAME
order by USERNAME;
set heading off
PROMPT
select 'SCHEMA SIZE: '||ceil(sum(bytes)/1024/1024)||' MB' from dba_segments where owner=UPPER('$USERNAME') group by owner;
PROMPT ------------
PROMPT
select 'Number of Invalid Objects: '||count(*) from dba_objects where STATUS = 'INVALID' and owner=upper('$USERNAME');
PROMPT --------------------------
PROMPT
select 'Number of Connected Sessions: ' || count(*) from gv\$session where username=upper('$USERNAME');
PROMPT -----------------------------
EOF
if [ -f "${SPOOL_FILE}" ]
then
echo;echo "The Creation Statement has been spooled in: ${SPOOL_FILE}"
echo
fi
# #############
# END OF SCRIPT
# #############
# REPORT BUGS to: mahmmoudadel@hotmail.com
# DISCLAIMER: THIS SCRIPT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY WARRANTY. IT IS PROVIDED "AS IS".
# DOWNLOAD THE LATEST VERSION OF DATABASE ADMINISTRATION BUNDLE FROM: http://dba-tips.blogspot.com/2014/02/oracle-database-administration-scripts.html
DBA_BUNDLE6/failed_logins.sh 0000740 0152073 0152061 00000017152 13775601664 015623 0 ustar oracle oinstall ###################################################
# This script retrieves the FAILED LOGIN ATTEMPTS.
# To be run by ORACLE user
# # # #
# Author: Mahmmoud ADEL # # # # ###
# Created: 25-02-2013 # # # # #
#
###################################################
#############
# Description:
#############
echo
echo "====================================================================="
echo "This script retrieve the FAILED LOGIN ATTEMPTS in the last n of days."
echo "====================================================================="
echo
sleep 1
# #######################################
# Excluded INSTANCES:
# #######################################
# Here you can mention the instances the script will IGNORE and will NOT run against:
# Use pipe "|" as a separator between each instance name.
# e.g. Excluding: -MGMTDB, ASM instances:
EXL_DB="\-MGMTDB|ASM|APX" #Excluded INSTANCES [Will not get reported offline].
#############################
# Listing Available Instances:
#############################
# Count Instance Numbers:
INS_COUNT=$( ps -ef|grep pmon|grep -v grep|egrep -v ${EXL_DB}|wc -l )
# Exit if No DBs are running:
if [ $INS_COUNT -eq 0 ]
then
echo No Database Running !
exit
fi
# If there is ONLY one DB set it as default without prompt for selection:
if [ $INS_COUNT -eq 1 ]
then
export ORACLE_SID=$( ps -ef|grep pmon|grep -v grep|egrep -v ${EXL_DB}|awk '{print $NF}'|sed -e 's/ora_pmon_//g'|grep -v sed|grep -v "s///g" )
# If there is more than one DB ASK the user to select:
elif [ $INS_COUNT -gt 1 ]
then
echo
echo "Select the Instance You Want To Run this script against:[Enter the number]"
echo "-------------------------------------------------------"
select DB_ID in $( ps -ef|grep pmon|grep -v grep|egrep -v ${EXL_DB}|awk '{print $NF}'|sed -e 's/ora_pmon_//g'|grep -v sed|grep -v "s///g" )
do
integ='^[1-9]+$'
if ! [[ ${REPLY} =~ ${integ} ]] || [ ${REPLY} -gt ${INS_COUNT} ]
then
echo
echo "Error: Not a valid number!"
echo
echo "Enter a valid NUMBER from the displayed list !: i.e. Enter a number from [1 to ${INS_COUNT}]"
echo "-----------------------------------------------"
else
export ORACLE_SID=$DB_ID
echo
printf "`echo "Selected Instance: ["` `echo -e "\033[33;5m${DB_ID}\033[0m"` `echo "]"`\n"
echo
break
fi
done
fi
# Exit if the user selected a Non Listed Number:
if [ -z "${ORACLE_SID}" ]
then
echo "You've Entered An INVALID ORACLE_SID"
exit
fi
# #########################
# Getting ORACLE_HOME
# #########################
ORA_USER=`ps -ef|grep ${ORACLE_SID}|grep pmon|grep -v grep|egrep -v ${EXL_DB}|awk '{print $1}'|tail -1`
USR_ORA_HOME=`grep ${ORA_USER} /etc/passwd| cut -f6 -d ':'|tail -1`
# SETTING ORATAB:
if [ -f /etc/oratab ]
then
ORATAB=/etc/oratab
export ORATAB
## If OS is Solaris:
elif [ -f /var/opt/oracle/oratab ]
then
ORATAB=/var/opt/oracle/oratab
export ORATAB
fi
# ATTEMPT1: Get ORACLE_HOME using pwdx command:
export PGREP=`which pgrep`
export PWDX=`which pwdx`
if [[ -x ${PGREP} ]] && [[ -x ${PWDX} ]]
then
PMON_PID=`pgrep -lf _pmon_${ORACLE_SID}|awk '{print $1}'`
export PMON_PID
ORACLE_HOME=`pwdx ${PMON_PID}|awk '{print $NF}'|sed -e 's/\/dbs//g'`
export ORACLE_HOME
fi
# ATTEMPT2: If ORACLE_HOME not found get it from oratab file:
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
## If OS is Linux:
if [ -f /etc/oratab ]
then
ORATAB=/etc/oratab
ORACLE_HOME=`grep -v '^\#' $ORATAB | grep -v '^$'| grep -i "^${ORACLE_SID}:" | perl -lpe'$_ = reverse' | cut -f3 | perl -lpe'$_ = reverse' |cut -f2 -d':'`
export ORACLE_HOME
## If OS is Solaris:
elif [ -f /var/opt/oracle/oratab ]
then
ORATAB=/var/opt/oracle/oratab
ORACLE_HOME=`grep -v '^\#' $ORATAB | grep -v '^$'| grep -i "^${ORACLE_SID}:" | perl -lpe'$_ = reverse' | cut -f3 | perl -lpe'$_ = reverse' |cut -f2 -d':'`
export ORACLE_HOME
fi
#echo "ORACLE_HOME from oratab is ${ORACLE_HOME}"
fi
# ATTEMPT3: If ORACLE_HOME is still not found, search for the environment variable: [Less accurate]
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
ORACLE_HOME=`env|grep -i ORACLE_HOME|sed -e 's/ORACLE_HOME=//g'`
export ORACLE_HOME
#echo "ORACLE_HOME from environment is ${ORACLE_HOME}"
fi
# ATTEMPT4: If ORACLE_HOME is not found in the environment search user's profile: [Less accurate]
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
ORACLE_HOME=`grep -h 'ORACLE_HOME=\/' $USR_ORA_HOME/.bash_profile $USR_ORA_HOME/.*profile | perl -lpe'$_ = reverse' |cut -f1 -d'=' | perl -lpe'$_ = reverse'|tail -1`
export ORACLE_HOME
#echo "ORACLE_HOME from User Profile is ${ORACLE_HOME}"
fi
# ATTEMPT5: If ORACLE_HOME is still not found, search for orapipe: [Least accurate]
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
ORACLE_HOME=`locate -i orapipe|head -1|sed -e 's/\/bin\/orapipe//g'`
export ORACLE_HOME
#echo "ORACLE_HOME from orapipe search is ${ORACLE_HOME}"
fi
# TERMINATE: If all above attempts failed to get ORACLE_HOME location, EXIT the script:
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
echo "Please export ORACLE_HOME variable in your .bash_profile file under oracle user home directory in order to get this script to run properly"
echo "e.g."
echo "export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1"
exit
fi
export LD_LIBRARY_PATH=${ORACLE_HOME}/lib
##########################################
# Exit if the user is not the Oracle Owner:
##########################################
CURR_USER=`whoami`
if [ ${ORA_USER} != ${CURR_USER} ]; then
echo ""
echo "You're Running This Sctipt with User: \"${CURR_USER}\" !!!"
echo "Please Run This Script With The Right OS User: \"${ORA_USER}\""
echo "Script Terminated!"
exit
fi
###########################
# SQLPLUS Section:
###########################
# PROMPT FOR VARIABLES:
######################
echo "How many days back you want to retrieve FAILED LOGIN ATTEMPTS to the Database? [Default 1]"
echo "-----------------------------------------------------------------------------"
while read NUM_DAYS
do
case $NUM_DAYS in
# NO VALUE PROVIDED:
"") NUM_DAYS=1;echo;echo "Retreiving FAILED LOGIN ATTEMPTS data in the last 24 Hours ... [Please Wait]";break ;;
# A NON NUMERIC VALUE PROVIDED:
*[!0-9]*) echo "Please enter a Valid NUMERIC Value:" ;;
*) echo;echo "Retreiving the FAILED LOGIN ATTEMPTS in the last [${NUM_DAYS}] Days ... [Please Wait]";break ;;
esac
done
############################
# Execution of SQL Statement:
############################
${ORACLE_HOME}/bin/sqlplus -S "/ as sysdba" < (sysdate -$NUM_DAYS)
order by 1;
EOF
###############
# END OF SCRIPT
###############
# REPORT BUGS to: .
# DISCLAIMER: THIS SCRIPT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY WARRANTY. IT IS PROVIDED "AS IS".
# DOWNLOAD THE LATEST VERSION OF DATABASE ADMINISTRATION BUNDLE FROM: http://dba-tips.blogspot.com/2014/02/oracle-database-administration-scripts.html
DBA_BUNDLE6/COLD_BACKUP.sh 0000740 0152073 0152061 00000037143 13775601642 014570 0 ustar oracle oinstall # ##################################################################################################
# Database COLD Backup Script.
# [Ver 1.6] # # #
# Author: Mahmmoud ADEL # # # # ###
# Created: 22-12-13 # # # # #
#
# Modified: 16-05-14 Increased linesize to avoid line breaking.
#
#
# ##################################################################################################
# ###########
# Description:
# ###########
echo
echo "==============================================="
echo "This script Takes a COLD BACKUP for a database."
echo "==============================================="
echo
sleep 1
# #######################################
# Excluded INSTANCES:
# #######################################
# Here you can mention the instances the script will IGNORE and will NOT run against:
# Use pipe "|" as a separator between each instance name.
# e.g. Excluding: -MGMTDB, ASM instances:
EXL_DB="\-MGMTDB|ASM|APX" #Excluded INSTANCES [Will not get reported offline].
# ###########################
# Listing Available Databases:
# ###########################
# Count Instance Numbers:
INS_COUNT=$( ps -ef|grep pmon|grep -v grep|egrep -v ${EXL_DB}|wc -l )
# Exit if No DBs are running:
if [ $INS_COUNT -eq 0 ]
then
echo No Database Running !
exit
fi
# If there is ONLY one DB set it as default without prompt for selection:
if [ $INS_COUNT -eq 1 ]
then
export ORACLE_SID=$( ps -ef|grep pmon|grep -v grep|egrep -v ${EXL_DB}|awk '{print $NF}'|sed -e 's/ora_pmon_//g'|grep -v sed|grep -v "s///g" )
# If there is more than one DB ASK the user to select:
elif [ $INS_COUNT -gt 1 ]
then
echo
echo "Select the ORACLE_SID:[Enter the number]"
echo ---------------------
select DB_ID in $( ps -ef|grep pmon|grep -v grep|egrep -v ${EXL_DB}|awk '{print $NF}'|sed -e 's/ora_pmon_//g'|grep -v sed|grep -v "s///g" )
do
integ='^[1-9]+$'
if ! [[ ${REPLY} =~ ${integ} ]] || [ ${REPLY} -gt ${INS_COUNT} ]
then
echo
echo "Error: Not a valid number!"
echo
echo "Enter a valid NUMBER from the displayed list !: i.e. Enter a number from [1 to ${INS_COUNT}]"
echo "-----------------------------------------------"
else
export ORACLE_SID=$DB_ID
echo
printf "`echo "Selected Instance: ["` `echo -e "\033[33;5m${DB_ID}\033[0m"` `echo "]"`\n"
echo
break
fi
done
fi
# Exit if the user selected a Non Listed Number:
if [ -z "${ORACLE_SID}" ]
then
echo "You've Entered An INVALID ORACLE_SID"
exit
fi
# #########################
# Getting ORACLE_HOME
# #########################
ORA_USER=`ps -ef|grep ${ORACLE_SID}|grep pmon|grep -v grep|egrep -v ${EXL_DB}|grep -v "\-MGMTDB"|awk '{print $1}'|tail -1`
USR_ORA_HOME=`grep -i "^${ORA_USER}:" /etc/passwd| cut -f6 -d ':'|tail -1`
# SETTING ORATAB:
if [ -f /etc/oratab ]
then
ORATAB=/etc/oratab
export ORATAB
## If OS is Solaris:
elif [ -f /var/opt/oracle/oratab ]
then
ORATAB=/var/opt/oracle/oratab
export ORATAB
fi
# ATTEMPT1: Get ORACLE_HOME using pwdx command:
export PGREP=`which pgrep`
export PWDX=`which pwdx`
if [[ -x ${PGREP} ]] && [[ -x ${PWDX} ]]
then
PMON_PID=`pgrep -lf _pmon_${ORACLE_SID}|awk '{print $1}'`
export PMON_PID
ORACLE_HOME=`pwdx ${PMON_PID}|awk '{print $NF}'|sed -e 's/\/dbs//g'`
export ORACLE_HOME
fi
# ATTEMPT2: If ORACLE_HOME not found get it from oratab file:
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
## If OS is Linux:
if [ -f /etc/oratab ]
then
ORATAB=/etc/oratab
ORACLE_HOME=`grep -v '^\#' ${ORATAB} | grep -v '^$'| grep -i "^${ORACLE_SID}:" | perl -lpe'$_ = reverse' | cut -f3 | perl -lpe'$_ = reverse' |cut -f2 -d':'`
export ORACLE_HOME
## If OS is Solaris:
elif [ -f /var/opt/oracle/oratab ]
then
ORATAB=/var/opt/oracle/oratab
ORACLE_HOME=`grep -v '^\#' ${ORATAB} | grep -v '^$'| grep -i "^${ORACLE_SID}:" | perl -lpe'$_ = reverse' | cut -f3 | perl -lpe'$_ = reverse' |cut -f2 -d':'`
export ORACLE_HOME
fi
fi
# ATTEMPT3: If ORACLE_HOME is in /etc/oratab, use dbhome command:
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
ORACLE_HOME=`dbhome "${ORACLE_SID}"`
export ORACLE_HOME
fi
# ATTEMPT4: If ORACLE_HOME is still not found, search for the environment variable: [Less accurate]
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
ORACLE_HOME=`env|grep -i ORACLE_HOME|sed -e 's/ORACLE_HOME=//g'`
export ORACLE_HOME
fi
# ATTEMPT5: If ORACLE_HOME is not found in the environment search user's profile: [Less accurate]
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
ORACLE_HOME=`grep -h 'ORACLE_HOME=\/' ${USR_ORA_HOME}/.bash_profile ${USR_ORA_HOME}/.*profile | perl -lpe'$_ = reverse' |cut -f1 -d'=' | perl -lpe'$_ = reverse'|tail -1`
export ORACLE_HOME
fi
# ATTEMPT6: If ORACLE_HOME is still not found, search for orapipe: [Least accurate]
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
if [ -x /usr/bin/locate ]
then
ORACLE_HOME=`locate -i orapipe|head -1|sed -e 's/\/bin\/orapipe//g'`
export ORACLE_HOME
fi
fi
# TERMINATE: If all above attempts failed to get ORACLE_HOME location, EXIT the script:
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
echo "Please export ORACLE_HOME variable in your .bash_profile file under oracle user home directory in order to get this script to run properly"
echo "e.g."
echo "export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1"
exit
fi
export LD_LIBRARY_PATH=${ORACLE_HOME}/lib
# #############################################
# Exit if the executer is not the Oracle Owner:
# #############################################
CURR_USER=`whoami`
if [ ${ORA_USER} != ${CURR_USER} ]; then
echo ""
echo "You're Running This Sctipt with User: \"${CURR_USER}\" !!!"
echo "Please Run This Script With The Right OS User: \"${ORA_USER}\""
echo "Script Terminated!"
exit
fi
# Neutralize login.sql file:
# #########################
# Existance of login.sql file under current working directory eliminates many functions during the execution of this script:
if [ -f ./login.sql ]
then
mv ./login.sql ./login.sql_NeutralizedBy${SCRIPT_NAME}
fi
# ################################
# Creating Backup & Restore Script:
# ################################
echo
echo "Enter the Backup location: [Full Path]"
echo "-------------------------"
while read LOC1
do
EXTEN=${ORACLE_SID}_`date '+%F'`
LOC2=${LOC1}/COLDBACKUP_${EXTEN}
/bin/mkdir -p ${LOC2}
if [ ! -d "${LOC2}" ]; then
echo "Provided Backup Location is NOT Exist/Writable !"
echo
echo "Please Provide a VALID Backup Location:"
echo "---------------------------------------"
else
echo
sleep 1
echo "Backup Location Validated."
echo
break
fi
done
BKPSCRIPT=${LOC2}/Cold_Backup.sh
RSTSCRIPT=${LOC2}/Restore_Cold_Backup.sh
BKPSCRIPTLOG=${LOC2}/Cold_Backup.log
RSTSCRIPTLOG=${LOC2}/Restore_Cold_Backup.log
# Creating the Cold Backup script:
echo
echo "Creating Cold Backup and Cold Restore Scripts ..."
sleep 1
cd ${LOC2}
${ORACLE_HOME}/bin/sqlplus -S "/ as sysdba" <.
# DISCLAIMER: THIS SCRIPT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY WARRANTY. IT IS PROVIDED "AS IS".
# DOWNLOAD THE LATEST VERSION OF DATABASE ADMINISTRATION BUNDLE FROM:
# http://dba-tips.blogspot.com/2014/02/oracle-database-administration-scripts.html
DBA_BUNDLE6/schedule_rman_image_copy_bkp.sh 0000740 0152073 0152061 00000014113 13526474761 020657 0 ustar oracle oinstall # ##############################################################################################
# Script to be used on crontab to schedule an RMAN Image/Copy Backup
VER="[1.2]"
# ##############################################################################################
# # # #
# Author: Mahmmoud ADEL # # # # ###
# Created: 01-10-17 # # # # #
#
# Modified: 02-10-17
# 10-03-19 Add the option of deleting old CONTROLFILE AUTOBACKUP files.
#
#
# ##############################################################################################
# VARIABLES Section: [Must be Modified for each Env]
# #################
# INSTANCE Name: [Replace ${ORACLE_SID} with your instance SID]
export ORACLE_SID=${ORACLE_SID}
# ORACLE_HOME Location: [Replace ${ORACLE_HOME} with the right ORACLE_HOME path]
export ORACLE_HOME=${ORACLE_HOME}
# Backup Location: [Replace /backup/rmancopy with the right backup location path]
export BACKUPLOC=/backup/rmancopy
# Backup LOG location:
export RMANLOG=${BACKUPLOC}/rmancopy.log
# Perform Maintenance based on below Backup & Archive Retention: [Y|N] [Default DISABLED]
MAINTENANCEFLAG=N
# Backup Retention "In Days": [Backups older than this retention will be deleted]
export BKP_RETENTION=7
# Archives Deletion "In Days": [Archivelogs older than this retention will be deleted]
export ARCH_RETENTION=7
# CONTROLFILE AUTOBACKUP Retention "In Days": [AUTOBACKUP of CONTROLFILE older than this retention will be deleted]
CTRL_AUTOBKP_RETENTION=7
# Show the full DATE and TIME details in the backup log:
export NLS_DATE_FORMAT='DD-Mon-YYYY HH24:MI:SS'
export ORACLE_SID
export ORACLE_HOME
export BACKUPLOC
export COMPRESSION
export BKP_RETENTION
export ARCH_RETENTION
export RMANLOG
export NLS_DATE_FORMAT
export MAINTENANCEFLAG
# Check the selected MAINTENANCE option:
case ${MAINTENANCEFLAG} in
Y|y|YES|Yes|yes|ON|on)
HASH_MAINT=""
export HASH_MAINT
;;
*)
HASH_MAINT="#"
export COMPRESSED_BKP
;;
esac
# Append the date to the backup log for each script execution:
echo "----------------------------" >> ${RMANLOG}
date >> ${RMANLOG}
echo "----------------------------" >> ${RMANLOG}
# ###################
# RMAN SCRIPT Section:
# ###################
${ORACLE_HOME}/bin/rman target / msglog=${RMANLOG} < ${LOGFILE}
fi
fi
# #######################################
# Excluded INSTANCES:
# #######################################
# Here you can mention the instances the script will IGNORE and will NOT run against:
# Use pipe "|" as a separator between each instance name.
# e.g. Excluding: -MGMTDB, ASM instances:
EXL_DB="\-MGMTDB|ASM|APX" #Excluded INSTANCES [Will not get reported offline].
# ##############################
# SCRIPT ENGINE STARTS FROM HERE ............................................
# ##############################
# ###########################
# Listing Available Databases:
# ###########################
# Count Instance Numbers:
INS_COUNT=$( ps -ef|grep pmon|grep -v grep|egrep -v ${EXL_DB}|wc -l )
# Exit if No DBs are running:
if [ $INS_COUNT -eq 0 ]
then
echo No Database Running !
exit
fi
# If there is ONLY one DB set it as default without prompt for selection:
if [ $INS_COUNT -eq 1 ]
then
export ORACLE_SID=$( ps -ef|grep pmon|grep -v grep|egrep -v ${EXL_DB}|awk '{print $NF}'|sed -e 's/ora_pmon_//g'|grep -v sed|grep -v "s///g" )
# If there is more than one DB ASK the user to select:
elif [ $INS_COUNT -gt 1 ]
then
echo
echo "Select the ORACLE_SID:[Enter the number]"
echo ---------------------
select DB_ID in $( ps -ef|grep pmon|grep -v grep|egrep -v ${EXL_DB}|awk '{print $NF}'|sed -e 's/ora_pmon_//g'|grep -v sed|grep -v "s///g" )
do
integ='^[1-9]+$'
if ! [[ ${REPLY} =~ ${integ} ]] || [ ${REPLY} -gt ${INS_COUNT} ]
then
echo
echo "Error: Not a valid number!"
echo
echo "Enter a valid NUMBER from the displayed list !: i.e. Enter a number from [1 to ${INS_COUNT}]"
echo "-----------------------------------------------"
else
export ORACLE_SID=$DB_ID
echo
printf "`echo "Selected Instance: ["` `echo -e "\033[33;5m${DB_ID}\033[0m"` `echo "]"`\n"
echo
break
fi
done
fi
# Exit if the user selected a Non Listed Number:
if [ -z "${ORACLE_SID}" ]
then
echo "You've Entered An INVALID ORACLE_SID"
exit
fi
# #########################
# Getting ORACLE_HOME
# #########################
ORA_USER=`ps -ef|grep ${ORACLE_SID}|grep pmon|grep -v grep|egrep -v ${EXL_DB}|grep -v "\-MGMTDB"|awk '{print $1}'|tail -1`
USR_ORA_HOME=`grep ${ORA_USER} /etc/passwd| cut -f6 -d ':'|tail -1`
# SETTING ORATAB:
if [ -f /etc/oratab ]
then
ORATAB=/etc/oratab
export ORATAB
## If OS is Solaris:
elif [ -f /var/opt/oracle/oratab ]
then
ORATAB=/var/opt/oracle/oratab
export ORATAB
fi
# ATTEMPT1: Get ORACLE_HOME using pwdx command:
export PGREP=`which pgrep`
export PWDX=`which pwdx`
if [[ -x ${PGREP} ]] && [[ -x ${PWDX} ]]
then
PMON_PID=`pgrep -lf _pmon_${ORACLE_SID}|awk '{print $1}'`
export PMON_PID
ORACLE_HOME=`pwdx ${PMON_PID}|awk '{print $NF}'|sed -e 's/\/dbs//g'`
export ORACLE_HOME
fi
#echo "ORACLE_HOME from PWDX is ${ORACLE_HOME}"
# ATTEMPT2: If ORACLE_HOME not found get it from oratab file:
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
## If OS is Linux:
if [ -f /etc/oratab ]
then
ORATAB=/etc/oratab
ORACLE_HOME=`grep -v '^\#' $ORATAB | grep -v '^$'| grep -i "^${ORACLE_SID}:" | perl -lpe'$_ = reverse' | cut -f3 | perl -lpe'$_ = reverse' |cut -f2 -d':'`
export ORACLE_HOME
## If OS is Solaris:
elif [ -f /var/opt/oracle/oratab ]
then
ORATAB=/var/opt/oracle/oratab
ORACLE_HOME=`grep -v '^\#' $ORATAB | grep -v '^$'| grep -i "^${ORACLE_SID}:" | perl -lpe'$_ = reverse' | cut -f3 | perl -lpe'$_ = reverse' |cut -f2 -d':'`
export ORACLE_HOME
fi
#echo "ORACLE_HOME from oratab is ${ORACLE_HOME}"
fi
# ATTEMPT3: If ORACLE_HOME is still not found, search for the environment variable: [Less accurate]
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
ORACLE_HOME=`env|grep -i ORACLE_HOME|sed -e 's/ORACLE_HOME=//g'`
export ORACLE_HOME
#echo "ORACLE_HOME from environment is ${ORACLE_HOME}"
fi
# ATTEMPT4: If ORACLE_HOME is not found in the environment search user's profile: [Less accurate]
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
ORACLE_HOME=`grep -h 'ORACLE_HOME=\/' $USR_ORA_HOME/.bash_profile $USR_ORA_HOME/.*profile | perl -lpe'$_ = reverse' |cut -f1 -d'=' | perl -lpe'$_ = reverse'|tail -1`
export ORACLE_HOME
#echo "ORACLE_HOME from User Profile is ${ORACLE_HOME}"
fi
# ATTEMPT5: If ORACLE_HOME is still not found, search for orapipe: [Least accurate]
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
ORACLE_HOME=`locate -i orapipe|head -1|sed -e 's/\/bin\/orapipe//g'`
export ORACLE_HOME
#echo "ORACLE_HOME from orapipe search is ${ORACLE_HOME}"
fi
# TERMINATE: If all above attempts failed to get ORACLE_HOME location, EXIT the script:
if [ ! -f ${ORACLE_HOME}/bin/sqlplus ]
then
echo "Please export ORACLE_HOME variable in your .bash_profile file under oracle user home directory in order to get this script to run properly"
echo "e.g."
echo "export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1"
exit
fi
export LD_LIBRARY_PATH=${ORACLE_HOME}/lib
# Neutralize login.sql file:
# #########################
# Existance of login.sql file under current working directory eliminates many functions during the execution of this script:
if [ -f ./login.sql ]
then
mv ./login.sql ./login.sql_NeutralizedBy${SCRIPT_NAME}
fi
# ###################################
# SQLPLUS: Getting All Sessions Info:
# ###################################
${ORACLE_HOME}/bin/sqlplus -s '/ as sysdba' << EOF
set feedback off
set pages 0
spool ${LOGFILE} APPEND
prompt
select 'Timestamp: '||to_char(sysdate, 'DD-Mon-YYYY HH24:MI:SS') from dual;
prompt ===================================
prompt Current sessions in the Database...
prompt ===================================
prompt
set feedback off linesize 220 pages 1000
col inst for 99
col module for a27
col event for a28
col MACHINE for a27
col "ST|WAITD|ACT_SINC|LOG_T" for a45
col "INST|USER|SID,SERIAL#" for a30
col "INS|USER|SID,SER|MACHIN|MODUL" for a72
select substr(s.INST_ID||'|'||s.USERNAME||'|'||s.sid||','||s.serial#||'|'||substr(s.MACHINE,1,25)||' | '||substr(s.MODULE,1,25),1,72)"INS|USER|SID,SER|MACHIN|MODUL"
--select s.INST_ID||'|'||s.USERNAME||' | '||s.sid||','||s.serial# "INST|USER|SID,SERIAL#"
--,substr(s.MODULE,1,27)"MODULE"
--,substr(s.MACHINE,1,27)"MACHINE"
,substr(s.status||'|'||round(w.WAIT_TIME_MICRO/1000000)||'|'||LAST_CALL_ET||'|'||to_char(LOGON_TIME,'ddMon HH24:MI'),1,45) "ST|WAITD|ACT_SINC|LOG_T"
,substr(w.event,1,28)"EVENT"
--,s.PREV_SQL_ID
,s.SQL_ID CURR_SQL_ID
from gv\$session s, gv\$session_wait w
where s.USERNAME is not null
and s.sid=w.sid
order by "ST|WAITD|ACT_SINC|LOG_T" desc, "INS|USER|SID,SER|MACHIN|MODUL";
--order by "ST|WA_ST|WAITD|ACT_SINC|LOG_T" desc, "INST|USER|SID,SERIAL#";
set pages 1000
col MACHINE for a70
col MODULE for a70
PROMPT
PROMPT SESSIONS Distribution:
PROMPT ----------------------
PROMPT PER MODULE:
select INST_ID,MODULE,count(*) "TOTAL_SESSIONS" from gv\$session group by INST_ID,module order by INST_ID,count(*) desc,MODULE;
PROMPT
PROMPT PER MACHINE:
select INST_ID,MACHINE,count(*) "TOTAL_SESSIONS" from gv\$session group by INST_ID,MACHINE order by INST_ID,count(*) desc,MACHINE;
PROMPT
set pages 0
select 'ACTIVE SESSIONS: '||count(*) from gv\$session where USERNAME is not null and status='ACTIVE';
select 'INACTIVE SESSIONS: '||count(*) from gv\$session where USERNAME is not null and status='INACTIVE';
select 'BACKGROUND SESSIONS: '||count(*) from gv\$session where USERNAME is null;
PROMPT -------------------- ------
select 'TOTAL SESSIONS: '||count(*) from gv\$session;
PROMPT
EOF
# De-Neutralize login.sql file:
# ############################
# If login.sql was renamed during the execution of the script revert it back to its original name:
if [ -f ./login.sql_NeutralizedBy${SCRIPT_NAME} ]
then
mv ./login.sql_NeutralizedBy${SCRIPT_NAME} ./login.sql
fi
# #############
# END OF SCRIPT
# #############
# REPORT BUGS to: .
# DISCLAIMER: THIS SCRIPT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY WARRANTY. IT IS PROVIDED "AS IS".
# DOWNLOAD THE LATEST VERSION OF DATABASE ADMINISTRATION BUNDLE FROM: http://dba-tips.blogspot.com/2014/02/oracle-database-administration-scripts.html