Friday, January 17, 2025

Incompatibilities

 SELECT

fctl.user_concurrent_program_name,

         DECODE (TO_RUN_TYPE, 'S', 'Set', 'Program') TYPE,

         DECODE (INCOMPATIBILITY_TYPE, 'G', 'Global', 'Domain')

            "Incompatibilty Type",

            fat.APPLICATION_NAME

            FROM apps.FND_CONCURRENT_PROGRAM_SERIAL fcrs,

         apps.FND_CONCURRENT_PROGRAMS_TL fctl,

         apps.FND_APPLICATION_TL fat

   WHERE     fcrs.RUNNING_APPLICATION_ID = fat.application_id

         and fctl.user_concurrent_program_name in ('Accounting Program','Create Accounting') -- CP id of the program in question

         AND fctl.CONCURRENT_PROGRAM_ID = fcrs.TO_RUN_CONCURRENT_PROGRAM_ID

         AND fctl.LANGUAGE = 'US'

         AND fat.LANGUAGE = 'US'

ORDER BY to_run_application_id, to_run_concurrent_program_id

Thursday, January 9, 2025

Mon1 Script

 [oracle@lufRAMfexanpq1-ekd5g3 ~]$ more $HOME/scripts/YE_Monitor_Running_ram.sh


LOG_FILE=$HOME/scripts/log/YE_Monitor_Running_jobs.log

. $HOME/.bash_profile > /dev/null

EMAIL_LIST="seetharam.nanubalu@RAM.gov"


PATH=/u02/app/oracle/product/19.0.0.0/dbhome_3/bin:/u02/app/oracle/product/19.0.0.0/dbhome_3/OPatch:$PATH; export PATH

ORACLE_UNQNAME=EBSST1; export ORACLE_UNQNAME

ORACLE_SID=EBSST13; export ORACLE_SID

ORACLE_HOSTNAME=lufRAMfexanpq1-ekd5g3.nonprodexadb.RAMfwest.oraclevcn.com; export ORACLE_HOSTNAME

LD_LIBRARY_PATH=/u02/app/oracle/product/19.0.0.0/dbhome_3/lib; export LD_LIBRARY_PATH

ORACLE_BASE=/u02/app/oracle; export ORACLE_BASE

OH=/u02/app/oracle/product/19.0.0.0/dbhome_3; export OH

ORACLE_HOME=/u02/app/oracle/product/19.0.0.0/dbhome_3; export ORACLE_HOME

TNS_ADMIN=/u02/app/oracle/product/19.0.0.0/dbhome_3/network/admin/EBSST1; export TNS_ADMIN


sqlplus -s / as sysdba >/dev/null <<EOF

### Connecting to a Container Database (CDB)

alter session set container=SRAM2I;

SET LINESIZE 160 PAGESIZE 200 FEEDBACK ON

SET ECHO OFF MARKUP HTML ON ENTMAP OFF SPOOL ON HEAD '' TABLE 'align=centre border=1 color:Black background:#f7f7e7'

SPOOL $LOG_FILE

PROMPT <h1>YE and Standard Concurrent Manager Status</h1>

select q.concurrent_queue_name || ' - ' || target_node qname,

       q.running_processes actual,

       q.max_processes target,

       sum(decode(r.phase_code,'R',1,0)) - sum(decode(r.status_code,'W',1,0)) running,

       sum(decode(r.phase_code,'P',1,0)) pending,

       nvl(sum(decode(r.status_code,'W',1,'H',1,'S',1,'A',1,'Z',1,0)),0) paused,

       nvl(sum(decode(r.status_code,'F',1,'Q',1,'B',1,'T',0)),0) influx,

       avg((nvl(r.actual_start_date,r.requested_start_date) - r.requested_start_date)*1440) avgqtime

  from applsys.fnd_concurrent_requests r,

       applsys.fnd_concurrent_processes p,

       applsys.fnd_concurrent_queues q

 where r.controlling_manager (+) = p.concurrent_process_id

   and p.queue_application_id = q.application_id

   and p.concurrent_queue_id = q.concurrent_queue_id

   and q.max_processes > 0

   and ((r.phase_code in ('R','P','I') and upper('N') = 'Y') or

         upper('N') != 'Y')

and q.concurrent_queue_name in( 'STANDARD','STANDARD2', 'YETSMANAGER')

 group by q.concurrent_queue_name || ' - ' || target_node, q.running_processes, q.max_processes;


PROMPT <h1> Stale Stats of FV and GL </h1>


select distinct OWNER,TABLE_NAME,PARTITION_NAME,SUBPARTITION_NAME,NUM_ROWS,LAST_ANALYZED,stale_stats from dba_tab_statistics where stale_stats='YES'

and owner in ('FV','GL') order by owner;


select distinct owner,INDEX_NAME,TABLE_NAME from DBA_IND_STATISTICS where stale_stats='YES' and owner in ('FV','GL') order by owner;


SPOOL OFF

EOF


echo "<html>" > $LOG_FILE.html

echo "<title>$MSUB</title>" >> $LOG_FILE.html

echo "<style>" >> $LOG_FILE.html

echo "  h1   {font:11pt Arial,Helvetica,sans-serif; color:black; background:White;line-height:0px;margin-top:16px;margin-bottom:0px;}" >> $LOG_FILE.html

echo "  body {font:10pt Arial,Helvetica,sans-serif; color:black; background:White;line-height:0px;margin-top:0px;margin-bottom:0px;}" >> $LOG_FILE.html

echo "</style>" >> $LOG_FILE.html

echo "<head>" >> $LOG_FILE.html

echo "<h3><b>$MSUB</b></h1>" >> $LOG_FILE.html

echo "<b>Enviroment:</b> $ORACLE_SID" >> $LOG_FILE.html

echo "<br><b>Context</b>: $CONTEXT_NAME<br>`date '+Date: %m/%d/%y  Time:%H:%M:%S'`<br>" >> $LOG_FILE.html

echo "</head><hr />" >> $LOG_FILE.html

echo "<body>" >> $LOG_FILE.html

cat $LOG_FILE >> $LOG_FILE.html

echo "</body>" >> $LOG_FILE.html

echo "</html>" >> $LOG_FILE.html


if [ `grep -ci "rows selected." $LOG_FILE` -ne 0 -o `grep -ci "row selected." $LOG_FILE` -ne 0 ];then

mailx -s "$(echo "$ORACLE_SID: 19c YE Specific Monitoring Details\n "Content-Type: text/html; charset=\"us-ascii\""")" -r ociNONPROD_donotreply@RAM.gov $EMAIL_LIST <YE_Monit

or_Running_jobs.log.html

fi



Monitoring Script

LOG_FILE=$HOME/scripts/log/Monitor_Running_jobs.log

. $HOME/.profile > /dev/null

EMAIL_LIST=seetharam.nanubalu@psc.RAM.gov

sqlplus -s / as sysdba >/dev/null <<EOF

SET LINESIZE 160 PAGESIZE 200 FEEDBACK ON

SET ECHO OFF MARKUP HTML ON ENTMAP OFF SPOOL ON HEAD '' TABLE 'align=centre border=1 color:Black background:#f7f7e7'

SPOOL $LOG_FILE

PROMPT <h1>YE and Standard Concurrent Manager Status</h1>

select q.concurrent_queue_name || ' - ' || target_node qname,

       q.running_processes actual,

       q.max_processes target,

       sum(decode(r.phase_code,'R',1,0)) - sum(decode(r.status_code,'W',1,0)) running,

       sum(decode(r.phase_code,'P',1,0)) pending,

       nvl(sum(decode(r.status_code,'W',1,'H',1,'S',1,'A',1,'Z',1,0)),0) paused,

       nvl(sum(decode(r.status_code,'F',1,'Q',1,'B',1,'T',0)),0) influx,

       avg((nvl(r.actual_start_date,r.requested_start_date) - r.requested_start_date)*1440) avgqtime

  from applsys.fnd_concurrent_requests r,

       applsys.fnd_concurrent_processes p,

       applsys.fnd_concurrent_queues q

 where r.controlling_manager (+) = p.concurrent_process_id

   and p.queue_application_id = q.application_id

   and p.concurrent_queue_id = q.concurrent_queue_id

   and q.max_processes > 0

   and ((r.phase_code in ('R','P','I') and upper('N') = 'Y') or

         upper('N') != 'Y')

and q.concurrent_queue_name in( 'STANDARD','STANDARD2', 'YETSMANAGER')

 group by q.concurrent_queue_name || ' - ' || target_node, q.running_processes, q.max_processes;


PROMPT <h1> Stale Stats of FV and GL </h1>


select distinct OWNER,TABLE_NAME,PARTITION_NAME,SUBPARTITION_NAME,NUM_ROWS,LAST_ANALYZED,stale_stats from dba_tab_statistics where stale_stats='YES'

and owner in ('FV','GL') order by owner;


select distinct owner,INDEX_NAME,TABLE_NAME from DBA_IND_STATISTICS where stale_stats='YES' and owner in ('FV','GL') order by owner;


PROMPT <h1> Locks </h1>

SELECT DECODE(request,0,'Holder: ','Waiter: ')||sid sess,

       id1, id2, lmode, request, type

FROM gv\$LOCK

WHERE (id1, id2, type) IN (SELECT id1, id2, type FROM gv\$LOCK WHERE request>0)   ORDER BY id1, request;



PROMPT <h1> Blocking Session Details </h1>


select 

   (select username from gv\$session where sid=a.sid) blocker,

   a.sid,

   ' is blocking ',

   (select username from gv\$session where sid=b.sid) blockee,

   b.sid

from 

   gv\$lock a, 

   gv\$lock b

where 

   a.block = 1

and 

   b.request > 0

and 

   a.id1 = b.id1

and 

   a.id2 = b.id2;


PROMPT <h1> Tables with locked stats GL and FV </h1>


SELECT owner,

       table_name,

       stattype_locked

FROM   dba_tab_statistics

WHERE  stattype_locked IS NOT NULL and owner in ('GL','FV')

ORDER BY owner, table_name;


PROMPT <h1> TOP 10 SQL statements that are using the most resources</h1>


SELECT *

FROM   (SELECT a.inst_id,a.sql_id,a.plan_hash_value,Substr(a.sql_text,1,50) sql_text,

               Trunc(a.disk_reads/Decode(a.executions,0,1,a.executions)) reads_per_execution, 

               a.buffer_gets, 

               a.disk_reads, 

               a.executions, 

               a.sorts,

               a.address

        FROM   gv\$sqlarea a

        ORDER BY 2 DESC)

WHERE  rownum <= 10;


PROMPT <h1> Library Cache locks and pin </h1>


select /*+ all_rows */ w1.sid waiting_session,

h1.sid holding_session,

w.kgllktype lock_or_pin,

w.kgllkhdl address,

decode(h.kgllkmod, 0, 'None', 1, 'Null', 2, 'Share', 3, 'Exclusive',

'Unknown') mode_held,

decode(w.kgllkreq, 0, 'None', 1, 'Null', 2, 'Share', 3, 'Exclusive',

'Unknown') mode_requested

from dba_kgllock w, dba_kgllock h, gv\$session w1, gv\$session h1

where

(((h.kgllkmod != 0) and (h.kgllkmod != 1)

and ((h.kgllkreq = 0) or (h.kgllkreq = 1)))

and

(((w.kgllkmod = 0) or (w.kgllkmod= 1))

and ((w.kgllkreq != 0) and (w.kgllkreq != 1))))

and w.kgllktype = h.kgllktype

and w.kgllkhdl = h.kgllkhdl

and w.kgllkuse = w1.saddr

and h.kgllkuse = h1.saddr;


PROMPT <h1> OCI Objects Invalid Status </h1>


select count(*) from dba_objects where object_name  like  'OCI_PO_IMPORT%' and status='INVALID';


PROMPT <h1> Mandatory Workflow Programs </h1>


select distinct(ARGUMENT_TEXT),USER_CONCURRENT_PROGRAM_NAME

,REQUEST_ID,REQUESTED_START_DATE, fcr.PHASE_CODE 

from apps.fnd_concurrent_requests fcr,

apps.fnd_concurrent_programs_vl fpl,

apps.fnd_application_vl fal

where  fcr.REQUESTED_START_DATE > trunc(sysdate)

--AND fcr.REQUESTED_START_DATE < sysdate

AND fcr.concurrent_program_id = fpl.concurrent_program_id

AND fcr.program_application_id = fpl.application_id

and fcr.program_application_id = fal.application_id

and user_concurrent_program_name = 'Workflow Background Process'

--and ARGUMENT_TEXT like ',%'

and fcr.PHASE_CODE in ('P','R')

ORDER BY ARGUMENT_TEXT DESC;


PROMPT <h1> Year End Specific Concurrent Programs </h1>


SELECT DISTINCT

  cq.concurrent_queue_name || ' - ' || target_node qname,

  cr.request_id "Req Id",

  TO_NUMBER(DECODE (cr.parent_request_id, -1, NULL, cr.parent_request_id)) "Parent Id",

  DECODE(SUBSTR(ct.user_concurrent_program_name,1,10),'Report Set',

         cr.description||' (Report Set)',ct.user_concurrent_program_name) "Concurrent Program", 

  pr.concurrent_program_name "Program", 

  us.user_name "User Name",

  to_char(cr.actual_start_date,'MM/DD HH24:MI:SS') "Start Date/Time",

  DECODE(cr.phase_code,

    'C', 'Completed', 'P', 'Pending', 

    'R', 'Running', 'I', 'Inactive','T','Terminated', 

    cr.phase_code) "Phase",

 DECODE(cr.status_code,

   'A', 'Waiting',  'B', 'Resuming',

   'C', 'Normal',   'D', 'Cancelled', 'E', 'Error', 

   'G', 'Warning',  'H', 'On Hold',   'I', 'Normal', 

   'Q', 'Standby',  'R', 'Normal',    'S', 'Suspended', 

   'U', 'Disabled', 'W', 'Paused',    'X', 'Terminated', 

   'F', 'Scheduled','M', 'NO Manager','T', 'Terminated',

   'Z', 'Waiting', cr.status_code) "Status",

 ROUND((NVL(actual_completion_date,SYSDATE)-actual_start_date)*1440,2) "Time (mins)",

 DECODE

   (cr.phase_code,'R',

    to_char(trunc( sysdate - cr.actual_start_date ),'FM0') || ':' ||

    to_char(trunc( mod( (sysdate - cr.actual_start_date)*24, 24 ) ), 'FM00') || ':' || 

    to_char(trunc( mod( (sysdate - cr.actual_start_date)*24*60, 60 ) ), 'FM00') || ':' ||

    to_char(trunc( mod( (sysdate - cr.actual_start_date)*24*60*60, 60 ) ), 'FM00') ,

    to_char(trunc( cr.actual_completion_date - cr.actual_start_date ),'FM0') || ':' ||

    to_char(trunc( mod( (cr.actual_completion_date - cr.actual_start_date)*24, 24 ) ), 'FM00') || ':' || 

    to_char(trunc( mod( (cr.actual_completion_date - cr.actual_start_date)*24*60, 60 ) ), 'FM00') || ':' ||

    to_char(trunc( mod( (cr.actual_completion_date - cr.actual_start_date)*24*60*60, 60 ) ), 'FM00') 

   ) "Time"

FROM 

  apps.fnd_Concurrent_requests cr,

  apps.fnd_concurrent_processes cp,

  apps.fnd_concurrent_queues cq,

  apps.fnd_concurrent_programs_tl ct,

  apps.fnd_concurrent_programs pr,

  apps.fnd_user us

WHERE cr.controlling_manager = cp.concurrent_process_id

  AND cr.concurrent_program_id = pr.concurrent_program_id

  AND cr.program_application_id = pr.application_id

  AND ct.concurrent_program_id = pr.concurrent_program_id

  AND cp.queue_application_id = cq.application_id

  AND cp.concurrent_queue_id = cq.concurrent_queue_id

  AND ct.language = 'US'

  AND cr.requested_by = us.user_id

  AND status_code = 'R'

AND ROUND((NVL(actual_completion_date,SYSDATE)-actual_start_date)*1440,2) >= 5

and ct.user_concurrent_program_name in ('Run MassAllocations',

'RAM Net Cost Allocation Program',

'Year End Closing Process',

'Add/Delete Summary Accounts',

'Open Period',

'Posting',

'Journal Import',

'RAM CFRS Trial Balance Extract',

'Open Encumbrance Year',

'Open Budget Year',

'GTAS / Data Act Processes',

'RAM GTAS - Update TPTAS Information',

'RAM GTAS Pre-Process',

'RAM GTAS Bulk File',

'Federal File Creation Process',

'Federal Accounts Creation Process',

'Federal Activity Attributes Creation',

'RAM CFRS Trial Balance Extract',

'RAM Consolidated CFRS/IDDA Extract Process',

'RAM Net Cost Allocation Program',

'RAM Budget Execution Configuration Roll Forward Process',

'RAM UDO Audit Extract Process',

'RAM GL Transactions Audit Extract Process',

'RAM Expense Audit Extract Process',

'RAM AR Audit Extract Process',

'RAM AP 2110 Audit Extract Process',

'RAM AP 2190 Audit Extract Process',

'RAM Cash Audit Extract Process',

'RAM Trial Balance Audit Extract Process',

'RAM Revenue Audit Extract Process')

ORDER BY ROUND((NVL(actual_completion_date,SYSDATE)-actual_start_date)*1440,2) DESC

/

PROMPT <h3><br>Year End Specific Concurrent Programs - Sessions</h3>

SELECT DISTINCT

  cr.request_id "Request ID",

  DECODE(SUBSTR(cptl.user_concurrent_program_name,1,10),'Report Set',

         cr.description||' (Report Set)',cptl.user_concurrent_program_name) ||'<br>'||

    '('||cr.argument_text||')' "Concurrent Program/Parameters", 

  'Queue name: '||cq.concurrent_queue_name || '<br>'||

  'APP Server: '||upper(target_node)|| '<br>'||

  'PID       : '||cr.os_process_id "APP Process",

  (select 

  'DB Server : '||upper(vi.host_name)||' Instance: '||vi.instance_name|| ' Instance id: '||vs.inst_id || '<br>'||

  'Session   : SID: '||vs.sid|| ' Serial#: '||vs.serial#||' PID: '||cr.oracle_process_id||' Status: '||vs.status|| '<br>'||

  'SQL ID    : '||vs.sql_id|| '<br>'||

  'Wait Event: '||w.event||'('||w.seconds_in_wait||') seconds'

   FROM gv\$session vs, gv\$process vp, gv\$instance vi, gv\$session_wait w

   WHERE vp.addr= vs.paddr

     AND vs.module is NOT NULL

     AND vs.audsid=cr.oracle_session_id

     AND vs.inst_id=vp.inst_id

     AND vs.inst_id=w.inst_id

     AND vs.inst_id=vi.inst_id

     AND w.sid=vs.sid

     AND rownum=1

  ) "DB Session"

from apps.fnd_concurrent_programs cp,

  apps.fnd_concurrent_programs_tl cptl,

  apps.fnd_concurrent_requests cr,

  applsys.fnd_USER us, 

  apps.fnd_concurrent_queues cq,

  apps.fnd_concurrent_processes cpp

where cp.application_id = cptl.application_id

  and cp.concurrent_program_id = cptl.concurrent_program_id

  and cptl.language='US'

  and cr.program_application_id = cp.application_id 

  and cr.concurrent_program_id = cp.concurrent_program_id

  and us.user_id = cr.requested_by

  AND cpp.queue_application_id = cq.application_id

  AND cpp.concurrent_queue_id = cq.concurrent_queue_id

  AND cr.controlling_manager = cpp.concurrent_process_id

  AND status_code = 'R'

and cptl.user_concurrent_program_name in ('Run MassAllocations',

'RAM Net Cost Allocation Program',

'Year End Closing Process',

'Add/Delete Summary Accounts',

'Open Period',

'Posting',

'Journal Import',

'RAM CFRS Trial Balance Extract',

'Open Encumbrance Year',

'Open Budget Year',

'GTAS / Data Act Processes',

'RAM GTAS - Update TPTAS Information',

'RAM GTAS Pre-Process',

'RAM GTAS Bulk File',

'Federal File Creation Process',

'Federal Accounts Creation Process',

'Federal Activity Attributes Creation',

'RAM CFRS Trial Balance Extract',

'RAM Consolidated CFRS/IDDA Extract Process',

'RAM Net Cost Allocation Program',

'RAM Budget Execution Configuration Roll Forward Process',

'RAM UDO Audit Extract Process',

'RAM GL Transactions Audit Extract Process',

'RAM Expense Audit Extract Process',

'RAM AR Audit Extract Process',

'RAM AP 2110 Audit Extract Process',

'RAM AP 2190 Audit Extract Process',

'RAM Cash Audit Extract Process',

'RAM Trial Balance Audit Extract Process',

'RAM Revenue Audit Extract Process') 

AND ROUND((NVL(actual_completion_date,SYSDATE)-actual_start_date)*1440,2) >= 5

/

PROMPT <h1>Regular Concurrent Programs</h1>

SELECT DISTINCT

  cq.concurrent_queue_name || ' - ' || target_node qname,

  cr.request_id "Req Id",

  TO_NUMBER(DECODE (cr.parent_request_id, -1, NULL, cr.parent_request_id)) "Parent Id",

  DECODE(SUBSTR(ct.user_concurrent_program_name,1,10),'Report Set',

         cr.description||' (Report Set)',ct.user_concurrent_program_name) "Concurrent Program",

  pr.concurrent_program_name "Program",

  us.user_name "User Name",

  to_char(cr.actual_start_date,'MM/DD HH24:MI:SS') "Start Date/Time",

  DECODE(cr.phase_code,

    'C', 'Completed', 'P', 'Pending',

    'R', 'Running', 'I', 'Inactive','T','Terminated',

    cr.phase_code) "Phase",

 DECODE(cr.status_code,

   'A', 'Waiting',  'B', 'Resuming',

   'C', 'Normal',   'D', 'Cancelled', 'E', 'Error',

   'G', 'Warning',  'H', 'On Hold',   'I', 'Normal',

   'Q', 'Standby',  'R', 'Normal',    'S', 'Suspended',

   'U', 'Disabled', 'W', 'Paused',    'X', 'Terminated',

   'F', 'Scheduled','M', 'NO Manager','T', 'Terminated',

   'Z', 'Waiting', cr.status_code) "Status",

 ROUND((NVL(actual_completion_date,SYSDATE)-actual_start_date)*1440,2) "Time (mins)",

 DECODE

   (cr.phase_code,'R',

    to_char(trunc( sysdate - cr.actual_start_date ),'FM0') || ':' ||

    to_char(trunc( mod( (sysdate - cr.actual_start_date)*24, 24 ) ), 'FM00') || ':' ||

    to_char(trunc( mod( (sysdate - cr.actual_start_date)*24*60, 60 ) ), 'FM00') || ':' ||

    to_char(trunc( mod( (sysdate - cr.actual_start_date)*24*60*60, 60 ) ), 'FM00') ,

    to_char(trunc( cr.actual_completion_date - cr.actual_start_date ),'FM0') || ':' ||

    to_char(trunc( mod( (cr.actual_completion_date - cr.actual_start_date)*24, 24 ) ), 'FM00') || ':' ||

    to_char(trunc( mod( (cr.actual_completion_date - cr.actual_start_date)*24*60, 60 ) ), 'FM00') || ':' ||

    to_char(trunc( mod( (cr.actual_completion_date - cr.actual_start_date)*24*60*60, 60 ) ), 'FM00')

   ) "Time"

FROM

  apps.fnd_Concurrent_requests cr,

  apps.fnd_concurrent_processes cp,

  apps.fnd_concurrent_queues cq,

  apps.fnd_concurrent_programs_tl ct,

  apps.fnd_concurrent_programs pr,

  apps.fnd_user us

WHERE cr.controlling_manager = cp.concurrent_process_id

  AND cr.concurrent_program_id = pr.concurrent_program_id

  AND cr.program_application_id = pr.application_id

  AND ct.concurrent_program_id = pr.concurrent_program_id

  AND cp.queue_application_id = cq.application_id

  AND cp.concurrent_queue_id = cq.concurrent_queue_id

  AND ct.language = 'US'

  AND cr.requested_by = us.user_id

  AND status_code = 'R'

--  AND ROUND((NVL(actual_completion_date,SYSDATE)-actual_start_date)*1440,2) >= 30

ORDER BY ROUND((NVL(actual_completion_date,SYSDATE)-actual_start_date)*1440,2) DESC

/

PROMPT <h1><br>Regular Concurrent Programs - Sessions</h1>

SELECT DISTINCT

  cr.request_id "Request ID",

  DECODE(SUBSTR(cptl.user_concurrent_program_name,1,10),'Report Set',

         cr.description||' (Report Set)',cptl.user_concurrent_program_name) ||'<br>'||

    '('||cr.argument_text||')' "Concurrent Program/Parameters",

  'Queue name: '||cq.concurrent_queue_name || '<br>'||

  'APP Server: '||upper(target_node)|| '<br>'||

  'PID       : '||cr.os_process_id "APP Process",

  (select

  'DB Server : '||upper(vi.host_name)||' Instance: '||vi.instance_name|| ' Instance id: '||vs.inst_id || '<br>'||

  'Session   : SID: '||vs.sid|| ' Serial#: '||vs.serial#||' PID: '||cr.oracle_process_id||' Status: '||vs.status|| '<br>'||

  'SQL ID    : '||vs.sql_id|| '<br>'||

  'Wait Event: '||w.event||'('||w.seconds_in_wait||') seconds'

   FROM gv\$session vs, gv\$process vp, gv\$instance vi, gv\$session_wait w

   WHERE vp.addr= vs.paddr

     AND vs.module is NOT NULL

     AND vs.audsid=cr.oracle_session_id

     AND vs.inst_id=vp.inst_id

     AND vs.inst_id=w.inst_id

     AND vs.inst_id=vi.inst_id

     AND w.sid=vs.sid

     AND rownum=1

  ) "DB Session"

from apps.fnd_concurrent_programs cp,

  apps.fnd_concurrent_programs_tl cptl,

  apps.fnd_concurrent_requests cr,

  applsys.fnd_USER us,

  apps.fnd_concurrent_queues cq,

  apps.fnd_concurrent_processes cpp

where cp.application_id = cptl.application_id

  and cp.concurrent_program_id = cptl.concurrent_program_id

  and cptl.language='US'

  and cr.program_application_id = cp.application_id

  and cr.concurrent_program_id = cp.concurrent_program_id

  and us.user_id = cr.requested_by

  AND cpp.queue_application_id = cq.application_id

  AND cpp.concurrent_queue_id = cq.concurrent_queue_id

  AND cr.controlling_manager = cpp.concurrent_process_id

  AND status_code = 'R'

--  AND ROUND((NVL(actual_completion_date,SYSDATE)-actual_start_date)*1440,2) >= 30

/


SPOOL OFF

EOF


echo "<html>" > $LOG_FILE.html

echo "<title>$MSUB</title>" >> $LOG_FILE.html

echo "<style>" >> $LOG_FILE.html

echo "  h1   {font:11pt Arial,Helvetica,sans-serif; color:black; background:White;line-height:0px;margin-top:16px;margin-bottom:0px;}" >> $LOG_FILE.html

echo "  body {font:10pt Arial,Helvetica,sans-serif; color:black; background:White;line-height:0px;margin-top:0px;margin-bottom:0px;}" >> $LOG_FILE.html

echo "</style>" >> $LOG_FILE.html

echo "<head>" >> $LOG_FILE.html

echo "<h3><b>$MSUB</b></h1>" >> $LOG_FILE.html

echo "<b>Enviroment:</b> $ORACLE_SID" >> $LOG_FILE.html

echo "<br><b>Context</b>: $CONTEXT_NAME<br>`date '+Date: %m/%d/%y  Time:%H:%M:%S'`<br>" >> $LOG_FILE.html

echo "</head><hr />" >> $LOG_FILE.html

echo "<body>" >> $LOG_FILE.html

cat $LOG_FILE >> $LOG_FILE.html

echo "</body>" >> $LOG_FILE.html

echo "</html>" >> $LOG_FILE.html


if [ `grep -ci "rows selected." $LOG_FILE` -ne 0 -o `grep -ci "row selected." $LOG_FILE` -ne 0 ];then

  mailx -s "$(echo "$ORACLE_SID: Running Concurrent Programs\nContent-Type: text/html")" $EMAIL_LIST < $LOG_FILE.html

fi


Tuesday, January 7, 2025

drr_wlsAutoStart

 #!/bin/bash

#

# +=====================================================================================+

# +=====================================================================================+

# |

# | FILENAME

# |  wlsAutoStart.sh

# |

# | DESCRIPTION

# |  A fully comprehensive script for starting and stopping complete FMW environments.

# |

# | USAGE

# |  Execute using the following syntax: wlsAutoStart.sh <command> [-session]

# |

# |  Where <command> is the main $control_command argument passed to fmw_srvctl();

# |  Refer to the AutoRestart User Guide for additional details.

# | 

# |  For internal use only, the following session flags are available:

# |   -d     Specifies this session was invoked by a daemon process.

# |   -e     Specifies this session was invoked by a CA script (EM).

# |   -m     Specifies this session was invoked by a Puppet (MCollective) agent.

# |   -r     Includes remote hosts when executing session.

# |

# | Created By

# |  Seetha Ram Nanubalu

# |

# | NOTES

# |  - The scripts invoked here should only affect the Application Tier. 

# |  - Required variables are inherited via $HOME/weblogic.properties (WLS AutoRestart)

# |  - Additional Python files should be available at $SHARED_SCRIPTS/onecommand

# |  - Silent operation can be inferred, as script contains no other input prompts.

# +=====================================================================================+



# Color Palette:

txtred=$'\e[0;31m'                 # Red

txtgrn=$'\e[0;32m'                 # Green

txtylw=$'\e[0;33m'                 # Yellow


# Text Effects

txtrst=$'\e[0m'                    # Text Reset

txtbld=$'\e[1m'                    # Text Bold

txtdim=$'\e[2m'                    # Text Dim

txtunl=$'\e[4m'                    # Text Underline

txtflsh=$'\e[5m'                   # Text Blink


# Input Arguments:

control_command=$1                  # Main command argument option for fmw_srvctl()

control_session=$2                  # Specifies if invoked session is local or remote


# Other runtime-variables:

debug_message=""                    # Debug Message string to be included in phone_home()

error_count=0                       # Initializes the error counter to zero

warning_count=0                     # Initializes the warning counter to zero

start_time=$(date +%s)              # Timestamp



unset_env() # Clears all other environment variables.

{

    PATH=$(getconf "PATH"):/sbin:/usr/sbin:$PATH

    

    unset $(env | cut -d= -f1 \

        | grep -Ev 'BASH|HOME|HOSTNAME|LANG|LOGNAME|PATH|SHELL|TERM|TZ|USER') 2>/dev/null

}


#hello() # Generates welcome banner.

#{

#    echo -e "\n\n\t\t${txtrst} ************************************\n\t\t *\c "

#    echo -e "${txtbld} Running FedMCS OneCommand Script ${txtrst}\c"

#    echo -e "*\n\t\t ************************************\n"

#}


get_my_version() # Determines this script version, no matter where it is being called from.

{

    source_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

    my_version=$(grep '$Header' $source_dir/${0##*/} | head -1 | awk '{print $4}')

    rel_v_date=$(grep '$Header' $source_dir/${0##*/} | head -1 | awk '{print $5}')

}


show_usage() # Prints basic help information.

{

    get_my_version

    echo -e "\n Release Version Info:\t$my_version\t$rel_v_date"

    

    echo -e "\n Usage:" 

    echo -e "\t ${0##*/} <command_option>"

    echo -e "\t Where <command_option> is a mandatory argument!"

    

    echo -e "\n Available arguments are:"

    echo -e "\t restart_AdminServer     Bounce the AdminServer on localhost"

    echo -e "\t restart_Domain          Bounce all components in the domain"

    echo -e "\t restart_ManagedServers  Bounce the Managed Servers simultaneously"

    echo -e "\t restart_NodeManager     Bounce the Node Manager(s) on localhost"

    echo -e "\t restart_OPMN            Bounce the HTTP Server on localhost"

    echo -e "\t start_AdminServer       Start the AdminServer on localhost"

    echo -e "\t start_Domain            Start all components in the domain"

    echo -e "\t start_ManagedServers    Start the Managed Servers simultaneously"

    echo -e "\t start_NodeManager       Start the Node Manager(s) on localhost"

    echo -e "\t start_OPMN              Start the HTTP Server on localhost"

    echo -e "\t status_AdminServer      Check the status of the AdminServer on localhost"

    echo -e "\t status_Domain           Check the status of all components in the domain"

    echo -e "\t status_ManagedServers   Check the status of the Managed Servers"

    echo -e "\t status_SystemComponents Check the status of the System Components"

    echo -e "\t status_NodeManager      Check the status of the Node Manager(s)"

    echo -e "\t status_OPMN             Check the status of the HTTP Server on localhost"

    echo -e "\t stop_AdminServer        Stop the AdminServer on localhost"

    echo -e "\t stop_Domain             Stop all components in the domain"

    echo -e "\t stop_ManagedServers     Stop the Managed Servers simultaneously"

    echo -e "\t stop_NodeManager        Stop the Node Manager(s) on localhost"

    echo -e "\t stop_OPMN               Stop the HTTP Server on localhost"


    echo -e "\n Other options:"

    echo -e "\t -? --help               Print this help message"

    

    echo -e "\n Example:"

    echo -e "\t ./${0##*/} restart_Domain\n"

    

    set_exit 2

}


set_logging() # Clears log file --by keeping only the 100 most recent sessions.

    log_file="$WLSAUTOSTART_LOG"

    

    if [[ $control_session == "-d" ]]; then

        session_type="daemon init.d script"

    elif [[ $control_session == "-e" ]]; then

        session_type="CA (EM) triggered event"

    elif [[ $control_session == "-m" ]]; then

        session_type="MCollective job request"

    elif [[ $control_session == "-r" ]]; then

        session_type="remote session"

    else

        session_type="local session"

    fi

    

    echo -e " - Clearing older sessions from $log_file: \t\c"

 #  echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

    

    if [[ ! -e $log_file ]]; then

        touch $log_file >/dev/null 2>&1

        chmod 777 $log_file >/dev/null 2>&1

        if (($?)); then

    ###        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtred} FAILED ${txtrst}]"

            debug_message+="[CRITICAL] $FUNCNAME(): "

            debug_message+="Unable to clear $log_file!"

            set_exit 126

        fi

    fi

    

    if [[ -w $log_file ]]; then

        while (($(grep -c "== OMCS OneCommand Session End ========" $log_file) > 99)); do

            printf "%s\n" 1d wq | ed -s $log_file

        done

       ### echo -e "\b\b\b\b\b\b\b\b\b\b\c"

# echo -e "[  OK ]"

       ### echo -e "[${txtgrn}   OK   ${txtrst}]"

        echo -e "\n========== OMCS OneCommand Session Start =========\n" >>$log_file

        echo -e "$(date) :: Running ${0##*/} on instance $instance_name" >>$log_file

        echo -e "Executing $control_command option on $f_hostname" >>$log_file

        echo -e "Release $my_version ($rel_v_date), called from: $source_dir" >>$log_file

        echo -e "This is a $session_type invoked by: $user_id\n" >>$log_file

    fi

}


set_wls_properties() # Imports $HOME/weblogic.properties file, and checks permissions.

{

    wls_profile="$HOME/weblogic.properties"

  

    if [[ -z $MW_HOME ]]; then

      MW_HOME=$ORACLE_HOME ; export MW_HOME

    fi


    if [[ -z $ASERVER_HOME ]]; then

      DOMAIN_HOME=$ASERVER_HOME ; export DOMAIN_HOME

    fi


    if [[ -z $MSERVER_HOME ]]; then

      DOMAIN_HOME_M=$MSERVER_HOME ; export DOMAIN_HOME_M

    fi


    echo -e " - Defining environmental variables: \t\t\t\c"

    #echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

    

    if (hostname -f >/dev/null 2>&1); then

        s_hostname=$(hostname -s | cut -d "." -f1)

        f_hostname=$(hostname -f | cut -d " " -f1)

    elif (getent hosts $(hostname) >/dev/null 2>&1); then

        s_hostname=$(getent hosts $(hostname) | awk '{print $2}' | cut -d "." -f1)

        f_hostname=$(getent hosts $(hostname) | awk '{print $2}')

    else

        s_hostname=$(echo $HOSTNAME | cut -d "." -f1)

        f_hostname=$(echo $HOSTNAME | cut -d " " -f1)

    fi

    

    if [[ -r $wls_profile ]]; then

        source $wls_profile

        admin_port=$(echo $adminURL | awk -F ":" '{print $2}')

        instance_name=$(echo $INSTANCE | tr "[:lower:]" "[:upper:]")

        instance_type=$(echo $DOMAIN_NAME | tr "[:upper:]" "[:lower:]")

        my_scripts=$SHARED_SCRIPTS/onecommand

        if [[ $INSTANCE_OWNER != $(whoami) ]]; then

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtred} FAILED ${txtrst}]"

            echo -e "\nRunning ${0##*/} as '$(whoami)'"

            echo -e "${0##*/} must be executed as '$INSTANCE_OWNER'"

            debug_message+="[CRITICAL] $FUNCNAME(): "

            debug_message+="Permission denied!"

            set_exit 126

        else

            get_wlst_properties

        fi    

    elif [[ ! -e $wls_profile ]] \

    && [[ $control_command == *"OPMN"* \

            || $control_command == *"NodeManager"* ]]; then

        get_ohs_properties

        if [[ -n $DOMAIN_HOME ]]; then

            get_nm_properties

        fi

        INSTANCE_OWNER=$instance_owner

        SHARED_SCRIPTS=/autofs/ood_repository/healthcheck

        WLSAUTOSTART_LOG="/tmp/wlsAutoStart.log"

    else

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtred} FAILED ${txtrst}]"

        echo -e "\nWLS AutoRestart must be implemented first!"

        instance_name=$(df -P | awk '$NF !~ /export/ {print $NF}' | grep -v "/dev/" \

            | cut -d "/" -f2 | tr "[:lower:]" "[:upper:]" | sort | uniq -c | sort -nr \

                | head  -1 | awk '{print $2}')

        debug_message+="[CRITICAL] $FUNCNAME(): "

        debug_message+="'$HOME/weblogic.properties' file not found!"

        set_exit 126

    fi

    

    if [[ -z $ADMIN_SERVER_NAME ]]; then

        ADMIN_SERVER_NAME="AdminServer"

    fi

    

    if [[ -z $DOMAIN_HOME_M ]]; then

        DOMAIN_HOME_M=$DOMAIN_HOME

    fi

    

    if [[ -z $NMPORT_M ]]; then

        local_nmport=$NMPORT

        shared_nmport=$NMPORT

    elif [[ -n $NMPORT_M ]]; then

        local_nmport=$NMPORT_M

        shared_nmport=$NMPORT

    else

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtred} FAILED ${txtrst}]"

        debug_message+="[CRITICAL] $FUNCNAME(): "

        debug_message+="NodeManager Port is not defined --invalid configuration!\n"

        set_exit 126

    fi   

    

   ## echo -e "\b\b\b\b\b\b\b\b\b\b\c"

    echo -e "[  OK ]"

}


get_ohs_properties() # For DMZ type Public-MT(s), it constructs OHS necessary variables.

{

    OPMN_HOMES=""

    DMZ_DOMAIN_HOME=""

    

    instance_name=$(df -P | awk '$NF !~ /export/ {print $NF}' | grep -v "/dev/" \

            | cut -d "/" -f2 | tr "[:lower:]" "[:upper:]" | sort | uniq -c | sort -nr \

                | head  -1 | awk '{print $2}')

    instance_dir=$(echo /$instance_name | tr "[:upper:]" "[:lower:]")

    instance_owner=$(ls -l $instance_dir | awk '{print $3}' | uniq -d)

    

    if [[ -d $instance_dir/local/config/domains/ohsdomain ]]; then

        DMZ_DOMAIN_HOME="$instance_dir/local/config/domains/ohsdomain"

        DOMAIN_HOME="$DMZ_DOMAIN_HOME"

    elif [[ -r /etc/oraInst.loc ]]; then

        inventory_loc=$(grep 'inventory_loc' /etc/oraInst.loc | awk -F "=" '{print $2}')

        if [[ -r $inventory_loc/logs ]]; then

            instance_homes=($(grep -h 'Instance Home:' \

                $inventory_loc/logs/installSummary* | awk -F ":" '{print $2}' | sort -u))

            for instance in ${instance_homes[@]}; do

                if [[ -d $instance/bin ]]; then

                    OPMN_HOMES="$OPMN_HOMES$instance:"

                fi

            done

        else

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtred} FAILED ${txtrst}]"

            debug_message+="[CRITICAL] $FUNCNAME(): "

            debug_message+="Unable to read file: '$inventory_loc/logs/installSummary*'!"

            set_exit 126

        fi   

    else

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtred} FAILED ${txtrst}]"

        debug_message+="[CRITICAL] $FUNCNAME(): "

        debug_message+="Unable to determine Instance Home(s)!"

        set_exit 126

    fi    

}


get_nm_properties() # For DMZ type Public-MT(s), it constructs NM necessary variables.

{

    NMPORT=""

    WLS_HOME=""

    

    nm_properties=$(find $instance_dir/local/fmw/*/wlserver*/ \

        -name ".product.properties")

    

    if [[ -n $nm_properties ]]; then

        NMPORT=$(grep NODEMGR_PORT $nm_properties | awk -F "=" '{print $2}')

        WLS_HOME=$(grep WL_HOME $nm_properties | awk -F "=" '{print $2}')

    else

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtred} FAILED ${txtrst}]"

        debug_message+="[CRITICAL] $FUNCNAME(): "

        debug_message+="Unable to read file: '$nm_properties'!"

        set_exit 126

    fi

}


create_config_files()

{


  echo -e "\r\rUser config files do not exist.  Creating now."

  echo -e "Enter weblogic password:"

  read p_password


echo "#############################################################################

#

#  CreateUserConfig.py

#

#############################################################################

import java.lang

import os

import string

import sys

protocol = \"t3://\"

username = sys.argv[1]

password = sys.argv[2]

adminURL = sys.argv[3]

domain = sys.argv[4]

URL = protocol + adminURL

adminUser = domain + \"/bin/scripts/secure/admUserConf.properties\"

adminPass = domain + \"/bin/scripts/secure/admPassKey.properties\"

redirect('/dev/null', 'false')


connect (username,password,URL)

storeUserConfig(userConfigFile=adminUser,userKeyFile=adminPass)

" > /tmp/foobar.py


  export WLST_PROPERTIES="-Dweblogic.management.confirmKeyfileCreation=true"

  $MW_HOME/oracle_common/common/bin/wlst.sh /tmp/foobar.py weblogic ${p_password} $adminURL $DOMAIN_HOME

  rm /tmp/foobar.py


}


get_wlst_properties() # Gets [ohsadmin] credentials and NodeManager listener type.  

{

    properties_file1=/home/oracle/.wlst/nm-cfg-soa_domain.props

    properties_file2=/home/oracle/.wlst/nm-key-soa_domain.props


    if [[ -f $properties_file1 && -f $properties_file2 ]]; then

        username=$properties_file1

        password=$properties_file2

    elif [[ -f $DOMAIN_HOME/nodemanager/nmUserConfig.properties ]]; then

mkdir -p $DOMAIN_HOME/bin/scripts/secure

cp $DOMAIN_HOME/nodemanager/nmUserConfig.properties $properties_file1

cp $DOMAIN_HOME/nodemanager/nmUserKey.properties $properties_file2

username=$properties_file1

        password=$properties_file2

    else

mkdir -p $DOMAIN_HOME/bin/scripts/secure

create_config_files

        username=$properties_file1

        password=$properties_file2

    fi

    

    if [[ -f $WLS_HOME/common/nodemanager/nodemanager.properties ]]; then

        nm_profile="$WLS_HOME/common/nodemanager/nodemanager.properties"

    elif [[ -f $DOMAIN_HOME/nodemanager/nodemanager.properties ]]; then

        nm_profile="$DOMAIN_HOME/nodemanager/nodemanager.properties"

        nm_profile_m="$DOMAIN_HOME_M/nodemanager/nodemanager.properties"

    elif [[ -f $NM_HOME/nodemanager.properties ]]; then

        nm_profile="$NM_HOME/nodemanager.properties"

        nm_profile_m="$NM_HOME/nodemanager.properties"

    else

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtred} FAILED ${txtrst}]"

        debug_message+="[CRITICAL] $FUNCNAME(): "

        debug_message+="Properties files cannot be located!"

        set_exit 126

    fi


    secure_listener=$(grep SecureListener $nm_profile | awk -F '=' '{print $2}')


    if [[ $secure_listener == "true" ]]; then

        connect_type="ssl"

    elif [[ $secure_listener == "false" ]]; then

        connect_type="plain"

    else # Connection type could not be determined; Defaulting to SSL

        connect_type="ssl"

    fi

    

    if [[ -r $nm_profile_m && -r $nm_profile ]]; then

        local_alias=$(grep ListenAddress $nm_profile_m | awk -F "=" '{print $2}')

        shared_alias=$(grep ListenAddress $nm_profile | awk -F "=" '{print $2}')

    else

        local_alias=$(grep ListenAddress $nm_profile | awk -F "=" '{print $2}')

    fi

}


get_context() # Runs WLST Offline to understand the execution context.

{

    local my_script=$my_scripts/getContext.py

    

    temp_server_file="/tmp/onecommand/server.txt"

    temp_machine_file="/tmp/onecommand/machines.txt"

    temp_prop_file="$HOME/weblogic.properties"


####    echo -e " - Probing execution context: \t\t\t\t\c" | tee -a $log_file

#    echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

    

    if [[ -x $MW_HOME/oracle_common/common/bin/wlst.sh ]]; then

        mkdir -p /tmp/onecommand

        $MW_HOME/oracle_common/common/bin/wlst.sh $my_script \

        $temp_prop_file $temp_server_file $temp_machine_file >>$log_file 2>&1

        given_machines=($(cat $temp_machine_file | awk -F ":" '{print $1}' | sort -u))

    else

##        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtred} FAILED ${txtrst}]"

        echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

        echo -e "Invalid path found for WLS_HOME in '$wls_profile'!"

        ((error_count++))

        set_exit 1

    fi

    

   for myhost in ${given_machines[@]}; do

       if [[ $myhost =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then

           given_hosts+=($(getent hosts $myhost | awk '{print $NF}' | cut -d '.' -f 1))

       else

           given_hosts+=(${myhost%%.*})

       fi

   done

    

   if ((${#given_hosts[@]} == 0)); then

       if [[ $control_session == "-m" ]]; then

       ###     echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#      echo -e "[  OK ]"

  ####          echo -e "[${txtgrn}   OK   ${txtrst}]"

           echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

           echo -e "Skipping, no further actions required for this host." >>$log_file

           set_exit 0

       else

           echo -e "\b\b\b\b\b\b\b\b\b\b\c"

           echo -e "[${txtred} FAILED ${txtrst}]"

           echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

           echo -e "No servers discovered reading the domain!\n" >>$log_file

           ((error_count++))

           set_exit 1

       fi

   else

     ###   echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#       echo -e "[  OK ]"

     ####   echo -e "[${txtgrn}   OK   ${txtrst}]"

     echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

     echo -e "Servers discovered in the domain:" >>$log_file

     printf "%s\n" "${given_hosts[@]}" >>$log_file

      echo -e "----------------\n" >>$log_file

    fi

}


validate_hosts() #Exa IP over Infiniband aliases need to be translated (e.g. ADM@Customer)

{

    remote_aliases=()

    

    for myhost in ${remote_hosts[@]}; do

        if (host $myhost >/dev/null 2>&1); then

            remote_aliases+=($myhost)

        else

            remote_aliases+=($(echo $myhost | sed 's/\-ipoib.*//g'))

        fi

    done

}


#check_ssh() # Checks for SSH User Equivalence among all know hosts.

#{

#    remote_hosts=()

#    ssh_enabled=0

    

#    echo -e " - Checking for SSH User Equivalence: \t\t\t\c" | tee -a $log_file

#    echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

    

#    for myhost in ${given_hosts[@]}; do

#        server_ip=$(getent hosts $myhost | awk '{print $1}' | head -1)

#        if (($((ifconfig -a || ip addr show) 2>/dev/null | grep -c $server_ip) < 1)); then

#            remote_hosts+=($myhost)

#        fi

#    done

    

#    for myhost in ${remote_hosts[@]}; do

#        returned_host=$(ssh -oStrictHostKeyChecking=no -oCheckHostIP=no -oBatchMode=yes \

#            $myhost echo "Hello World!" 2>&1)

#        if (($?)); then

#            break

#        else

#            ((ssh_enabled++))

#        fi

#    done

    

#    validate_hosts

    

#    if ((${#remote_hosts[@]} > 0)); then

#        echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

#        echo -e "Remote hosts identified:" >>$log_file 

 #       printf "%s\n" "${remote_aliases[@]}" >>$log_file

  #      echo -e "----------------" >>$log_file

  #  else

  #      echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

  #      echo -e "No Remote hosts identified" >>$log_file 

  #  fi


  #  if (($ssh_enabled != 0)) && (($ssh_enabled == ${#remote_hosts[@]})); then

  #      ssh_enabled="true"

  #      echo -e "\b\b\b\b\b\b\b\b\b\b\c"

  #      echo -e "[${txtgrn}   OK   ${txtrst}]"

  #      echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

  #      echo -e "User Equivalence is enabled between all machines!\n" >>$log_file

  #  elif ((${#remote_hosts[@]} == 0)); then

  #      echo -e "\b\b\b\b\b\b\b\b\b\b\c"

  #      echo -e "[${txtgrn}   OK   ${txtrst}]"

  #      echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

  #      echo -e "User Equivalence not required on single node instances\n" >>$log_file

  #  else

  #      ssh_enabled="false"

  #      echo -e "\b\b\b\b\b\b\b\b\b\b\c"

  #      echo -e "[${txtred} FAILED ${txtrst}]"

  #      echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

  #      echo -e "User Equivalence is not enabled on all machines!" >>$log_file

  #      echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

  #      echo -e "Unable to control component(s) for each remote host!" >>$log_file

  #      echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

  #      echo -e "Please run the genKey.sh and combineKey.sh scripts, as \c" >>$log_file

  #      echo -e "per the WLS AutoRestart - Setup Instructions!" >>$log_file

  #      ((error_count++))

  #  fi

#}


check_db() # Performs database availability check(s).

    local my_script=$my_scripts/dbCheck.sh

    

    echo -e " - Performing database availability checks: \t\t\c" | tee -a $log_file

#    echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

    

    source $my_script >>$log_file 2>&1

    

    if (is_db_check >>$log_file 2>&1); then

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtgrn}   OK   ${txtrst}]"

        echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

        echo -e "dbTier test passed!\n" >>$log_file

    else

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtred} FAILED ${txtrst}]"

        echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

        echo -e "Error occurred running ${my_script##*/}!\n" >>$log_file

        ((error_count++))

        set_exit 1

    fi

}


check_ports() # Check to see if the AdminServer or NodeManager(s) are actively listening.

{

    local check_option=$1

    

    case $check_option in

        admin_server)

            if (($(netstat -an | grep $admin_port | grep -c "LISTEN") >= 1)); then

                return 0

            else

                return 1

            fi

            ;;

        local_nm)

            if (($(netstat -an | grep $local_nmport | grep -c "LISTEN") >= 1)); then

                return 0

            else

                return 1

            fi

            ;;

        shared_nm)

            if (($(netstat -an | grep $shared_nmport | grep -c "LISTEN") >= 1)); then

                return 0

            else

                return 1

            fi

            ;;   

    esac

}


check_adminserver() # Check the status of the AdminServer, if running on localhost.

{

    echo -e "   > AdminServer status \c"

    

    if (check_ports admin_server); then

        echo -e "\n[INFO] ${FUNCNAME[1]}(): \c" >>$log_file

        echo -e "AdminServer is running on \c" >>$log_file

        echo -e "($s_hostname:$(echo $adminURL \

            | awk -F ":" '{print $2}'))\t\t\c" | tee -a $log_file

echo -e "[   OK   ]"

 ###WGG       echo -e "[${txtgrn}   OK   ${txtrst}]"

    else

        echo -e "\n[WARNING] ${FUNCNAME[1]}(): \c" >>$log_file

        echo -e "AdminServer is not running on \c" >>$log_file

        echo -e "($s_hostname:$(echo $adminURL \

            | awk -F ":" '{print $2}'))\t\t\c" | tee -a $log_file

        echo -e "[${txtylw} NOTICE ${txtrst}]"

        ((health_counter++))

    fi

}


check_nodemanager() # Checks the status of the Node Manager(s), including remote hosts.

{       

    local control_option=$1

    

    echo -e "   > NodeManager status \c"

    

    if (check_ports local_nm); then

        echo -e "\n[INFO] ${FUNCNAME[1]}(): \c" >>$log_file

        echo -e "NodeManager is running on \c" >>$log_file

        echo -e "($s_hostname:$local_nmport)\t\t\c" | tee -a $log_file

echo -e "[   OK   ]"

###WG        echo -e "[${txtgrn}   OK   ${txtrst}]"

    else

        echo -e "\n[WARNING] ${FUNCNAME[1]}(): \c" >>$log_file

        echo -e "NodeManager is not running on \c" >>$log_file

        echo -e "($s_hostname:$local_nmport)\t\t\c" | tee -a $log_file

        echo -e "[${txtylw} NOTICE ${txtrst}]"

        ((health_counter++))

    fi 

    

    if (check_ports shared_nm) && [[ $local_nmport != $shared_nmport ]]; then

        echo -e "   > NodeManager status \c"

        echo -e "\n[INFO] ${FUNCNAME[1]}(): \c" >>$log_file

        echo -e "NodeManager is running on \c" >>$log_file

        echo -e "($s_hostname:$shared_nmport)\t\t\c" | tee -a $log_file 

        echo -e "[${txtgrn}   OK   ${txtrst}]"

    elif ! (check_ports shared_nm) && [[ $local_nmport != $shared_nmport ]]; then

        echo -e "   > NodeManager status \c"

        echo -e "\n[WARNING] ${FUNCNAME[1]}(): \c" >>$log_file

        echo -e "NodeManager is not running on \c" >>$log_file

        echo -e "($s_hostname:$shared_nmport)\t\t\c" | tee -a $log_file

        echo -e "[${txtylw} NOTICE ${txtrst}]"

        ((health_counter++))

    fi 

    

    if [[ $control_option == "-r" ]]; then

        i_name=0; for myhost in ${remote_hosts[@]}; do  

            myhost_ip=$(getent hosts $myhost | awk '{print $1}')

            my_nmport=$(grep $myhost $temp_machine_file | awk -F ":" '{print $2}' \

                ; grep $myhost_ip $temp_machine_file | awk -F ":" '{print $2}')

            bash -c "cat </dev/null >/dev/tcp/$myhost_ip/$my_nmport" >/dev/null 2>&1

            if (($?)); then

                echo -e "   > NodeManager status \c"

                echo -e "\n[WARNING] ${FUNCNAME[1]}(): \c" >>$log_file

                echo -e "NodeManager is not running on \c" >>$log_file

                echo -e "(${remote_aliases[$i_name]}:$my_nmport)\t\t\c" | tee -a $log_file

                echo -e "[${txtylw} NOTICE ${txtrst}]"

                ((health_counter++))

            else

                echo -e "   > NodeManager status \c"

                echo -e "\n[INFO] ${FUNCNAME[1]}(): \c" >>$log_file

                echo -e "NodeManager is running on \c" >>$log_file

                echo -e "(${remote_aliases[$i_name]}:$my_nmport)\t\t\c" | tee -a $log_file

                echo -e "[${txtgrn}   OK   ${txtrst}]"

            fi

        ((i_name++))

        done

    fi

}


check_managedservers() # Checks the status of all the Managed Servers.

{

    local my_script=$my_scripts/statusMS.py

    local my_exit_code=""

    

    echo -e "   > ManagedServer(s) status \t\t\t\t\c"

#    echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

    

    oIFS=$IFS

    IFS=$'\n'

    

    if (check_ports admin_server); then

        echo -e "\n\n[INFO] $FUNCNAME(): \c" >>$log_file

        echo -e "Retrieving state of all Managed Servers" >>$log_file

        $MW_HOME/oracle_common/common/bin/wlst.sh $my_script $wls_profile >>$log_file 2>&1

        my_exit_code=$?

        if [[ $my_exit_code == 0 ]]; then

    ###        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[  OK  ]\n"

##WG    echo -e "[${txtgrn}   OK   ${txtrst}]\n"

            echo -e "\n[INFO] ${FUNCNAME[1]}(): \c" >>$log_file

            echo -e "All ManagedServers are running and in a healthy state" >>$log_file

            ms_status_messages_all=($(tac $log_file \

                | awk '/- End ManagedServer /{p=1; next} \

                    p && /- Start ManagedServer /{exit} p' \

                        | tac | sed '/AdminServer/d'))

        elif [[ $my_exit_code == 3 ]]; then

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtylw} NOTICE ${txtrst}]\n"

            echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

            echo -e "Not all ManagedServers are running or in a healthy state" >>$log_file

            ms_status_messages_all=($(tac $log_file \

                | awk '/- End ManagedServer /{p=1; next} \

                    p && /- Start ManagedServer /{exit} p' \

                        | tac | sed '/AdminServer/d'))

            ((health_counter++))

        else

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtred} FAILED ${txtrst}]\n"

            echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

            echo -e "Error occurred running ${my_script##*/}!\n" >>$log_file

            ((error_count++))        

        fi

    else

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtred} FAILED ${txtrst}]"

        echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

        echo -e "AdminServer is not running on \c" >>$log_file

        echo -e "$local_alias:$(echo $adminURL | awk -F ":" '{print $2}')" >>$log_file

    fi

    

    if ((${#ms_status_messages_error[@]} > 0)); then

        ms_status_messages=("${ms_status_messages_error[@]}")

    else

        ms_status_messages=("${ms_status_messages_all[@]}")

    fi

    

    if ((${#ms_status_messages[@]} > 0)); then

        for server_status in ${ms_status_messages[@]}; do

            echo -e "\t$server_status"

        done

        echo -e ""

    else

        echo -e "\tUnable to retrieve server state!\n"

    fi

        

    IFS=$oIFS

}


check_systemcomponents() # Checks the status of all the Managed Servers.

{

    local my_script=$my_scripts/statusSCP.py

    local my_exit_code=""

    

    echo -e "   > SystemComponent(s) status \t\t\t\t\c"

#    echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

    

    oIFS=$IFS

    IFS=$'\n'

    

    if (check_ports admin_server); then

        echo -e "\n\n[INFO] $FUNCNAME(): \c" >>$log_file

        echo -e "Retrieving state of all System Components" >>$log_file

        $MW_HOME/oracle_common/common/bin/wlst.sh $my_script $wls_profile >>$log_file 2>&1

        my_exit_code=$?

        if [[ $my_exit_code == 0 ]]; then

###            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[  OK ]\n" 

###WG      echo -e "[${txtgrn}   OK   ${txtrst}]\n"

            echo -e "\n[INFO] ${FUNCNAME[1]}(): \c" >>$log_file

            echo -e "All SystemComponents are running and in a healthy state" >>$log_file

            scp_status_messages_all=($(tac $log_file \

                | awk '/- End SystemComponent /{p=1; next} \

                    p && /- Start SystemComponent /{exit} p' \

                        | tac | sed '/AdminServer/d'))

        elif [[ $my_exit_code == 1 ]]; then

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtylw}   NA   ${txtrst}]\n"

            echo -e "\n[NOTICE] $FUNCNAME(): \c" >>$log_file

            echo -e "There are no system components registered in this environment" >>$log_file

            scp_status_messages_all="There are no system components registered"

        elif [[ $my_exit_code == 3 ]]; then

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtylw} NOTICE ${txtrst}]\n"

            echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

            echo -e "Not all SystemComponents are running or in a healthy state" >>$log_file

            scp_status_messages_all=($(tac $log_file \

                | awk '/- End SystemComponent /{p=1; next} \

                    p && /- Start SystemComponent /{exit} p' \

                        | tac | sed '/AdminServer/d'))

            ((health_counter++))

        else

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtred} FAILED ${txtrst}]\n"

            echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

            echo -e "Error occurred running ${my_script##*/}!\n" >>$log_file

            ((error_count++))        

        fi

    else

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtred} FAILED ${txtrst}]"

        echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

        echo -e "AdminServer is not running on \c" >>$log_file

        echo -e "$local_alias:$(echo $adminURL | awk -F ":" '{print $2}')" >>$log_file

    fi

    

    if ((${#scp_status_messages_error[@]} > 0)); then

        scp_status_messages=("${scp_status_messages_error[@]}")

    else

        scp_status_messages=("${scp_status_messages_all[@]}")

    fi

    

    if ((${#scp_status_messages[@]} > 0)); then

        for component_status in ${scp_status_messages[@]}; do

            echo -e "\t$component_status"

        done

        echo -e ""

    else

        echo -e "\tUnable to retrieve component state!\n"

    fi

        

    IFS=$oIFS

}


##check_deployments() # Checks the status of all WebLogic deployments in this domain.

#{

#    local my_script=$my_scripts/statusAD.py

#    local my_exit_code=""

    

#    echo -e "   > Application Deployment status \t\t\t\c"

#    echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

    

#    oIFS=$IFS

#    IFS=$'\n'

    

#    $MW_HOME/oracle_common/common/bin/wlst.sh $my_script \

#        $username $password $adminURL >>$log_file 2>&1

#    my_exit_code=$?

#    if [[ $my_exit_code == 0 ]]; then

#        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#        echo -e "[${txtgrn}   OK   ${txtrst}]"

#        echo -e "\n[INFO] ${FUNCNAME[1]}(): \c" >>$log_file

#        echo -e "All deployed applications are active\n" >>$log_file

#        app_active_status_count=$(tac $log_file \

#            | awk '/- End Application List -/{p=1; next} p \

#                && /- Start Application List -/{exit} p' \

#                    | cut -d ']' -f 2- | grep -c 'STATE_ACTIVE')

#        app_inactive_status_count=$(tac $log_file \

#            | awk '/- End Application List -/{p=1; next} p \

#                && /- Start Application List -/{exit} p' \

#                    | cut -d ']' -f 2- | grep -cv 'STATE_ACTIVE')

#    elif [[ $my_exit_code == 3 ]]; then

#        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#        echo -e "[${txtylw} NOTICE ${txtrst}]\n"

#        echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

#        echo -e "Not all deployed applications are active!\n" >>$log_file

#        app_active_status_count=$(tac $log_file \

#            | awk '/- End Application List -/{p=1; next} p \

#                && /- Start Application List -/{exit} p' \

#                    | cut -d ']' -f 2- | grep -c 'STATE_ACTIVE')

#        app_inactive_status_count=$(tac $log_file \

#            | awk '/- End Application List -/{p=1; next} p \

#                && /- Start Application List -/{exit} p' \

#                    | cut -d ']' -f 2- | grep -cv 'STATE_ACTIVE')

#        app_status_messages_error=($(tac $log_file \

#            | awk '/- End Application List -/{p=1; next} p \

#                && /- Start Application List -/{exit} p' \

#                    | cut -d ']' -f 2- | cut -f1 -d"," | sed -e 's/^[ \t]*//' \

#                        | sort -u | tac| grep -v 'STATE_ACTIVE'))

#        ((health_counter++))    

#    else

#        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#        echo -e "[${txtred} FAILED ${txtrst}]"

#        echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

#        echo -e "Error occurred running ${my_script##*/}!\n" >>$log_file

#        ((error_count++))           

#    fi

    

#    IFS=$oIFS

    

#    if ((${#app_status_messages_error[@]} > 0)); then

#        for app_status in "${app_status_messages_error[@]:0:9}"; do

#            echo -e "\t$app_status"

#        done

#        if ((${#app_status_messages_error[@]} > 10)); then

#            echo -e "\t..."

#        fi

#        echo -e "\n\tActive Count: ${txtgrn}$app_active_status_count${txtrst}\c"

#        echo -e "\tInactive Count: ${txtred}$app_inactive_status_count${txtrst}\n"

#    elif [[ -n $app_active_status_count ]]; then

#        echo -e "\n\tActive Count: ${txtgrn}$app_active_status_count${txtrst}\c"

#        echo -e "\tInactive Count: ${txtgrn}$app_inactive_status_count${txtrst}\n"

#    fi

#}


#check_composites() # Lists all Composite Applications deployed to the SOA platform.

#{

#    local my_script=$my_scripts/statusCA.py

#    local my_exit_code=""

#    

#    SOA_ORACLE_HOME=$(grep -iv '^#' $DOMAIN_HOME/bin/setDomainEnv.sh \

#        | grep -w SOA_ORACLE_HOME= | awk -F "=" '{print $2}' \

#            | sed "s/^\([\"']\)\(.*\)\1\$/\2/g" | sort -u)

#    

#    oIFS=$IFS

#    IFS=$'\n'

#    

#    if [[ -n $SOA_ORACLE_HOME ]]; then

#        echo -e "   > SOA Composites status \t\t\t\t\c"

#        echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

#        $MW_HOME/oracle_common/common/bin/wlst.sh $my_script \

#            $username $password $adminURL >>$log_file 2>&1

#        my_exit_code=$?

#        if [[ $my_exit_code == 0 ]]; then

#            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#            echo -e "[${txtgrn}   OK   ${txtrst}]"

#            echo -e "\n[INFO] ${FUNCNAME[1]}(): \c" >>$log_file

#            echo -e "All deployed composites are active\n" >>$log_file

#            comp_up_sum=$(tac $log_file | awk '/= End SOA Composites list =/{p=1; next} p \

#                && /= Start SOA Composites list =/{exit} p' \

#                    | awk 'match($0,/Up Count: [0-9]+/) {print substr($0, RSTART, RLENGTH)}' \

#                        | awk '{ SUM += $3} END { print SUM }')

#            comp_down_sum=$(tac $log_file | awk '/= End SOA Composites list =/{p=1; next} p \

#                && /= Start SOA Composites list =/{exit} p' \

#                    | awk 'match($0,/Down Count: [0-9]+/) {print substr($0, RSTART, RLENGTH)}' \

#                        | awk '{ SUM += $3} END { print SUM }')

#        elif [[ $my_exit_code == 2 ]]; then

#            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#            echo -e "[${txtylw} NOTICE ${txtrst}]\n"

#            echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

#            echo -e "Error occurred running ${my_script##*/}!\n" >>$log_file

#            ((warning_count++))

#        elif [[ $my_exit_code == 3 ]]; then

#            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#            echo -e "[${txtylw} NOTICE ${txtrst}]\n"

#            echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

#            echo -e "Not all deployed composites are active!\n" >>$log_file

#            comp_up_sum=$(tac $log_file | awk '/= End SOA Composites list =/{p=1; next} p \

#                && /= Start SOA Composites list =/{exit} p' \

#                    | awk 'match($0,/Up Count: [0-9]+/) {print substr($0, RSTART, RLENGTH)}' \

#                        | awk '{ SUM += $3} END { print SUM }')

#            comp_down_sum=$(tac $log_file | awk '/= End SOA Composites list =/{p=1; next} p \

#                && /= Start SOA Composites list =/{exit} p' \

#                    | awk 'match($0,/Down Count: [0-9]+/) {print substr($0, RSTART, RLENGTH)}' \

#                        | awk '{ SUM += $3} END { print SUM }')

#            comp_status_messages_error=($(tac $log_file \

#                | awk '/- End SOA Composites Down -/{p=1; next} p \

#                    && /- Start SOA Composites Down -/{exit} p' \

#                        | cut -d ']' -f 2- | cut -f1 -d"," \

#                            | sed -e 's/^[ \t]*//' | sort -u | tac))

#            ((health_counter++))

#        else

#            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#            echo -e "[${txtred} FAILED ${txtrst}]"

#            echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

#            echo -e "Error occurred running ${my_script##*/}!\n" >>$log_file

#            ((error_count++))

#        fi

#    fi      

    

#    IFS=$oIFS

    

#    if ((${#comp_status_messages_error[@]} > 0)); then

#        for comp_status in "${comp_status_messages_error[@]:0:9}"; do

#            echo -e "\t$comp_status"

#        done

#        if ((${#comp_status_messages_error[@]} > 10)); then

#            echo -e "\t..."

#        fi

#        echo -e "\n\tUp Count: ${txtgrn}$comp_up_sum${txtrst}\c"

#        echo -e "\t\tDown Count: ${txtred}$comp_down_sum${txtrst}\n"

#    elif [[ -n $comp_up_sum ]]; then

#        echo -e "\n\tUp Count: ${txtgrn}$comp_up_sum${txtrst}\c"

#        echo -e "\t\tDown Count: ${txtgrn}$comp_down_sum${txtrst}\n"

#    fi

#}


#check_jdbc() # Checks the status of all the JDBC data sources in this domain.

#{

#    local my_script=$my_scripts/statusJDBC.py

#    local my_exit_code=""

#    

#    echo -e "   > JDBC data sources status \t\t\t\t\c"

#    echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

#    

#    oIFS=$IFS

#    IFS=$'\n'

#    

#    echo -e "\n[INFO] ${FUNCNAME[1]}(): \c" >>$log_file

#    echo -e "Testing JDBC data sources" >>$log_file

#    

#    $MW_HOME/oracle_common/common/bin/wlst.sh $my_script \

#        $username $password $adminURL >>$log_file 2>&1

#    my_exit_code=$?

#    if [[ $my_exit_code == 0 ]]; then

#        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#        echo -e "[${txtgrn}   OK   ${txtrst}]"

#        echo -e "\n[INFO] ${FUNCNAME[1]}(): \c" >>$log_file

#        echo -e "All JDBC Data Sources are running\n" >>$log_file

#    elif [[ $my_exit_code == 3 ]]; then

#        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#        echo -e "[${txtylw} NOTICE ${txtrst}]\n"

#        echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

#        echo -e "Not all JDBC Data Sources are running!\n" >>$log_file

#        ds_status_messages_error=($(tac $log_file \

#            | awk '/- End Datasource List -/{p=1; next} p \

#                && /- Start Datasource List -/{exit} p' \

#                    | tac | cut -d ']' -f 2- | sort -u | grep ' => FAILED'))

#        ((health_counter++))

#    else

#        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#        echo -e "[${txtred} FAILED ${txtrst}]"

#        echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

#        echo -e "Error occurred running ${my_script##*/}!\n" >>$log_file       

#        ((error_count++))

#    fi

#    

#    if ((${#ds_status_messages_error[@]} > 0)); then

#        for ds_status in ${ds_status_messages_error[@]}; do

#            echo -e "\t$ds_status" | sed -e "s/FAILED/${txtred}FAILED${txtrst}/g"

#        done

#        if ((${#ds_status_messages_error[@]} > 10)); then

#            echo -e "\t...\n"

#        fi

#        echo -e ""

#    fi

#        

#    IFS=$oIFS  

#}


#check_urls() # Verifies all URLs defined in OHS.

#{

#    local my_script=$my_scripts/urlCheck.sh

#    local my_exit_code=""

#    local url_domain_strings=()

    

#    echo -e "   > URL status (modWebLogic Locations, HTTP 200/401)\t\c"

#    echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

    

#    oIFS=$IFS

#    IFS=$'\n'

    

#    $my_script >>$log_file 2>&1

#    my_exit_code=$?

#    if [[ $my_exit_code == 0 ]]; then

#        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#        echo -e "[${txtgrn}   OK   ${txtrst}]\n"

#        echo -e "\n[INFO] ${FUNCNAME[1]}(): \c" >>$log_file

#        echo -e "urlCheck test passed!\n" >>$log_file

#        url_status_messages_all=($(tac $log_file \

#            | awk '/- End URL List -/{p=1; next} p && /- Start URL List -/{exit} p' \

#                | awk '{ print length($0) " " $0; }' | sort -u | sort -rn | cut -d ' ' -f 2- | tac))

#    elif [[ $my_exit_code == 3 ]]; then

#        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#        echo -e "[${txtylw} NOTICE ${txtrst}]\n"

#        echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

#        echo -e "At least one or more URLs are unreachable!\n" >>$log_file

#        url_status_messages_all=($(tac $log_file \

#            | awk '/- End URL List -/{p=1; next} p && /- Start URL List -/{exit} p' \

#                | awk '{ print length($0) " " $0; }' | sort -u | sort -rn | cut -d ' ' -f 2- | tac))

#        ((health_counter++))

#    else

#        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#        echo -e "[${txtred} FAILED ${txtrst}]"

#        echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

#        echo -e "Error occurred running ${my_script##*/}!\n" >>$log_file

#        ((error_count++))

#    fi

        

    # Ignore previous style url_status_messages_error[@];

    # Always display all URLs regardless of status.

    url_status_messages=("${url_status_messages_all[@]}")

    

    # Extract domain from URL.

    for url_string in ${url_status_messages[@]}; do

        url_domain_strings+=($(echo $url_string | awk -F "/" '{print $3}' | awk -F ":" '{print $1}'))

    done

     

    # Clean array to retain only the distinct domain URL strings.

    uniq_domain_strings=($(echo "${url_domain_strings[@]}" | tr ' ' '\n' | sort -ru))


    # Trim URL output for readability, and print as a tree.

#    if ((${#url_status_messages[@]} > 0)); then

#        for url_domain_string in ${uniq_domain_strings[@]}; do

#            echo -e "\t$url_domain_string"

#            url_branches=${#url_status_messages[@]}

#            for url_status in ${url_status_messages[@]}; do

#                if ((url_branches == 1)); then

#                   #tree_path_prefix="└──"

#                    tree_path_prefix="|->"

#

#                elif ((url_branches == ${#url_status_messages[@]}));then

#                   #tree_path_prefix="├──"

#                    tree_path_prefix="|->"

#                fi

#                echo -e "$url_status" | grep $url_domain_string \

#                    | cut -d '/' -f 4- | sed 's/ => //g' \

#                        | sed -e "s/OK/${txtgrn}  OK  ${txtrst}/g" \

#                            | sed -e "s/Error/${txtred}  Error  ${txtrst}/g" \

#                                | xargs -I "%" echo -e "\t$tree_path_prefix .../%"

#                ((url_branches--))

#            done

#        done

#    fi


#    IFS=$oIFS

#}


#check_opmn() # Checks the status of all OPMN  instances.

#{

#    local control_option=$1

#    local running_count=0

#    local my_script=$my_scripts/statusOHS.py

#    local my_exit_code=""

#    

#    oIFS=$IFS

#    IFS=':'

#    opmn_paths=($OPMN_HOMES)

#    IFS=""

#    opmn_paths=(${opmn_paths[@]})

#    IFS=$oIFS

#    

#    if [[ -z $OPMN_HOMES ]]; then

#      echo -e "   > OPMN process status ($s_hostname)   \t\t\c"

#      echo -e "[${txtylw}   NA   ${txtrst}]"

#      echo -e "\n[N/A] $FUNCNAME(): \c" >>$log_file

#      echo -e "There are no OPMN instances registered in this environment\n" >>$log_file

#      echo -e "\n\tThere are no OPMN instances registered\n"

#    elif ((${#opmn_paths[@]} > 0)); then         

#      echo -e "   > OPMN process status ($s_hostname)   \t\t\c"

#      echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

#      for instance in ${opmn_paths[@]}; do

#          if [[ -d "$instance/bin" && $instance != "/" ]]; then

#              if (($($instance/bin/opmnctl status | grep -c "Alive") >= 1)); then

#                  echo -e "[INFO] $FUNCNAME(): \c" >>$log_file

#                  echo -e "Instance home $instance is running!" >>$log_file

#                  ((running_count++))

#              else

#                  echo -e "[WARNING] $FUNCNAME(): \c" >>$log_file

#                  echo -e "Instance home $instance is not running!" >>$log_file

#              fi

#          else

#              echo -e "[WARNING] $FUNCNAME(): \c" >>$log_file

#              echo -e "Skipping invalid instance $instance!" >>$log_file

#              ((warning_count++))

#              fi

#      done

#      if [[ $running_count ==  ${#opmn_paths[@]} ]]; then

#          echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#          echo -e "[${txtgrn}   OK   ${txtrst}]"

#          echo -e "\n[INFO] ${FUNCNAME[1]}(): \c" >>$log_file

#          echo -e "All OHS processes are running on localhost!" >>$log_file

#      else

#          echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#          echo -e "[${txtylw} NOTICE ${txtrst}]"

#          echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

#          echo -e "At least one OHS process is not running on localhost!" >>$log_file

#          ((warning_count++))

#      fi

#    else

#      echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#      echo -e "[${txtred} FAILED ${txtrst}]"

#      echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

#      echo -e "Not able to find components in environment!\n" >>$log_file

#      ((error_count++))

#    fi

#    

#    if [[ $control_option == "-r" && $ssh_enabled == "true" ]]; then

#        i_name=0; for myhost in ${remote_hosts[@]}; do

#   if [[ -z $OPMN_HOMES ]]; then

#            echo -e "   > OPMN process status ($myhost)   \t\t\c"

#          echo -e "[${txtylw}   NA   ${txtrst}]"

#          echo -e "\n[N/A] $FUNCNAME(): \c" >>$log_file

#          echo -e "There are no OPMN instances registered in this environment\n" >>$log_file

#          echo -e "\n\tThere are no OPMN instances registered\n"

#   else 

#            echo -e "   > OPMN process status (${remote_aliases[$i_name]})   \t\t\c"

#            echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

#            ssh -oStrictHostKeyChecking=no -oCheckHostIP=no $myhost $SHARED_SCRIPTS/"${0##*/}" status_OPMN -r >/dev/null 2>&1

#            if (($?)); then

#                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#                echo -e "[${txtylw} NOTICE ${txtrst}]"

#                echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

#                echo -e "Something didn't go as planned; \c" >>$log_file

#                echo -e "See $log_file on ${remote_aliases[$i_name]} for more details!\n" >>$log_file

#                ((warning_count++))

#            else

#                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#                echo -e "[${txtgrn}   OK   ${txtrst}]"

#                echo -e "\n[INFO] ${FUNCNAME[1]}(): \c" >>$log_file

#                echo -e "All OHS processes are running on $myhost; \c" >>$log_file

#                echo -e "See $log_file on ${remote_aliases[$i_name]} for more details\n" >>$log_file

#            fi

#      fi

#        ((i_name++))

#        done

#    elif [[ $control_option == "-l" ]]; then

#        i_name=0; for myhost in ${remote_hosts[@]}; do

#            myhost_ip=$(getent hosts $myhost | awk '{print $1}')

#            my_nmport=$(grep $myhost $temp_machine_file | awk -F ":" '{print $2}' \

#                ; grep $myhost_ip $temp_machine_file | awk -F ":" '{print $2}')

#            echo -e "   > OPMN process status (${remote_aliases[$i_name]})   \t\t\c"

#            echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

#            echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

#            echo -e "Retrieving component state for ${remote_aliases[$i_name]}" >>$log_file

#            $MW_HOME/oracle_common/common/bin/wlst.sh $my_script \

#                $DOMAIN_NAME $my_nmport $myhost \

#                    $username $password $connect_type ${remote_aliases[$i_name]} >>$log_file 2>&1

#            my_exit_code=$?

#            if [[ $my_exit_code == 0 ]]; then

#                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#                echo -e "[${txtgrn}   OK   ${txtrst}]"

#                echo -e "\n[INFO] ${FUNCNAME[1]}(): \c" >>$log_file

#                echo -e "OHS is running on ${remote_aliases[$i_name]}\n" >>$log_file

#            elif [[ $my_exit_code == 3 ]]; then

#                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#                echo -e "[${txtylw} NOTICE ${txtrst}]"

#                echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

#                echo -e "OHS is not running on ${remote_aliases[$i_name]}!\n" >>$log_file

#                ((health_counter++))

#            else

#                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

#                echo -e "[${txtred} FAILED ${txtrst}]"

#                echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

#                echo -e "Error occurred running ${my_script##*/} for ${remote_aliases[$i_name]}!\n" >>$log_file

#                ((error_count++))

#            fi

#        ((i_name++))

#        done

#    fi

#}


check_health() # Performs overall sanity check(s).

{

    local check_option=$1

    

    health_counter=0

    

    echo -e " - Beginning health checks: \n" | tee -a $log_file

    

    case $check_option in

        adminserver)

            check_adminserver

            ;;

        managedservers)

            check_managedservers

            ;;

        systemcomponents)

            check_systemcomponents

            ;;

        nodemanager)

            check_nodemanager

            ;;

        opmn)

            check_opmn

            ;;

        domain)

            check_adminserver

            check_nodemanager -r

            check_managedservers

            check_systemcomponents

#            check_jdbc

#            check_deployments

#            check_composites

#     check_opmn -r

#            check_urls

            ;;

    esac

    

    if (($health_counter > 0)); then

        ((warning_count++))

        health_check="failed"

    else

        health_check="passed"

    fi

    

    echo -e "\n - Completed health checks." | tee -a $log_file 

}


is_adminserver() # Checks if AdminServer is configured to run on this machine.

{

####    echo -e " - Checking to see if this box is AdminServer: \t\t\c" | tee -a $log_file

#    echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

    

    local listen_id=$(cat $temp_server_file | grep $ADMIN_SERVER_NAME | awk -F ":" '{print $2}')

    

    if [[ $listen_id != "All Local Addresses" ]]; then

        local listen_ip=$(getent hosts $listen_id | awk '{print $1}')

    fi

    

    if [[ -z $listen_id ]]; then

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtred} FAILED ${txtrst}]"

        echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

        echo -e "Error identifying AdminServer Listen Address; \c" >>$log_file

        echo -e "Possible non-standard configuration!\n" >>$log_file

        ((error_count++))

        set_exit 1

    elif [[ $listen_id == "All Local Addresses" ]]; then

    ###    echo -e "\b\b\b\b\b\b\b\b\b\b\c"

           echo -e "[ OK ]"      

    ###   echo -e "[${txtgrn}   OK   ${txtrst}]"

        echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

        echo -e "$s_hostname is the AdminServer\n" >>$log_file 

        return 0

    elif [[ -z $listen_ip ]]; then

        listen_ip=$listen_id

        echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

        echo -e "AdminServer IP address is '$listen_ip'" >>$log_file

    else

        echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

        echo -e "AdminServer hostname is '$listen_id'" >>$log_file

    fi

    

    if (($((ifconfig -a || ip addr show) 2>/dev/null | grep -c $listen_ip) > 0)); then

      ###  echo -e "\b\b\b\b\b\b\b\b\b\b\c"

      ###  echo -e "[${txtgrn}   OK   ${txtrst}]"

           echo -e "[ OK ]"

        echo -e "[INFO] $FUNCNAME(): \c" >>$log_file

        echo -e "$s_hostname is the AdminServer\n" >>$log_file 

        return 0

    else

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtred} FAILED ${txtrst}]"

        echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

        echo -e "Please execute ${0##*/} on \c" >>$log_file

        echo -e "$listen_id!\n" >>$log_file

        ((error_count++))

        set_exit 1

    fi

}


start_adminserver() # Starts AdminServer if not already running on localhost.

{

    local my_script=$my_scripts/startAdmin.py


    echo -e " - Starting AdminServer: \t\t\t\t\c" | tee -a $log_file

#    echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

    

    if (check_ports admin_server); then

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtylw} NOTICE ${txtrst}]"

        echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

        echo -e "AdminServer already running on $local_alias!\n" >>$log_file

        ((warning_count++))

    else

        $MW_HOME/oracle_common/common/bin/wlst.sh $my_script \

            $DOMAIN_NAME $DOMAIN_HOME $shared_nmport $HostName \

                $username $password $connect_type $ADMIN_SERVER_NAME >>$log_file 2>&1

        if (($?)); then

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtred} FAILED ${txtrst}]"

            echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

            echo -e "A problem occurred while running ${my_script##*/}!\n" >>$log_file

            ((error_count++))

        else

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtgrn}   OK   ${txtrst}]"

            echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

            echo -e "AdminServer has been started on $local_alias\n" >>$log_file

        fi

    fi

}


stop_adminserver() # Stops AdminServer if already running on localhost.

{

    local my_script=$my_scripts/stopAdmin.py


    echo -e " - Stopping AdminServer: \t\t\t\t\c" | tee -a $log_file

#    echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"


    if (check_ports admin_server); then

        $MW_HOME/oracle_common/common/bin/wlst.sh $my_script \

            $DOMAIN_NAME $DOMAIN_HOME $shared_nmport $HostName \

                $username $password $connect_type $ADMIN_SERVER_NAME >>$log_file 2>&1

        if (($?)); then

            echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

            echo -e "A problem occurred while running ${my_script##*/}; \c" >>$log_file

            echo -e "Trying another method, using stopWebLogic.sh!\n" >>$log_file

            ((warning_count++))

            $DOMAIN_HOME/bin/stopWebLogic.sh >>$log_file 2>&1

            if (($?)); then

                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                echo -e "[${txtred} FAILED ${txtrst}]"

                echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

                echo -e "A problem occurred while running stopWebLogic.sh!\n" >>$log_file

                ((error_count++))

            else

                while (check_ports admin_server); do

                    sleep 1

                done

                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                echo -e "[${txtgrn}   OK   ${txtrst}]"

                echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

                echo -e "AdminServer has been stopped on $local_alias\n" >>$log_file

            fi

        else

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtgrn}   OK   ${txtrst}]"

            echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

            echo -e "AdminServer has been stopped on $local_alias\n" >>$log_file

        fi

    else

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtylw} NOTICE ${txtrst}]"

        echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

        echo -e "AdminServer is not running on localhost!\n" >>$log_file

        ((warning_count++))

    fi

}


start_managedservers() # Starts all the Managed Servers not running in this domain.

{

    local my_script=$my_scripts/startMS.py

    

    echo -e " - Starting Managed Servers: \t\t\t\t\c" | tee -a $log_file

#    echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

    

    if (check_ports admin_server); then

        $MW_HOME/oracle_common/common/bin/wlst.sh $my_script $wls_profile >>$log_file 2>&1

        if (($?)); then

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtred} FAILED ${txtrst}]"

            echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

            echo -e "A problem occurred while running ${my_script##*/}!\n" >>$log_file

            ((error_count++))

        else

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtgrn}   OK   ${txtrst}]"

            echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

            echo -e "All Managed Servers have been started\n" >>$log_file

        fi

    else

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtylw} NOTICE ${txtrst}]"

        echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

        echo -e "AdminServer is not running on localhost!\n" >>$log_file

        ((warning_count++))

    fi

}


stop_managedservers() # Stops all Managed Servers running in this domain.

{

    local my_script=$my_scripts/stopMS.py

    

    echo -e " - Stopping Managed Servers: \t\t\t\t\c" | tee -a $log_file

#    echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

    

    if (check_ports admin_server); then

        $MW_HOME/oracle_common/common/bin/wlst.sh $my_script $wls_profile >>$log_file 2>&1

        if (($?)); then

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtred} FAILED ${txtrst}]"

            echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

            echo -e "A problem occurred while running ${my_script##*/}!\n" >>$log_file

            ((error_count++))

        else

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtgrn}   OK   ${txtrst}]"

            echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

            echo -e "All Managed Servers have been stopped\n" >>$log_file

        fi 

    else

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtylw} NOTICE ${txtrst}]"

        echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

        echo -e "AdminServer is not running on localhost!\n" >>$log_file

        ((warning_count++))

    fi

}


start_nodemanager() # Starts the NodeManagers, applies to WebLogic Server 11g & 12c.

{

    local control_option=$1

    

    check_db

    

    echo -e " - Starting NodeManager(s) on localhost: \t\t\c" | tee -a $log_file

#    echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"  

    

    if (check_ports local_nm) && (check_ports shared_nm); then

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtylw} NOTICE ${txtrst}]"

        echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

        echo -e "All Node Managers are already running on localhost!\n" >>$log_file

        ((warning_count++))

    else

        if [[ -f $DOMAIN_HOME/bin/startNodeManager.sh ]]; then

            nohup $DOMAIN_HOME/bin/startNodeManager.sh >>$log_file 2>&1 &

            if [[ ! -z $DOMAIN_HOME_M && $DOMAIN_HOME != $DOMAIN_HOME_M && \

                    -f $DOMAIN_HOME_M/bin/startNodeManager.sh ]]; then

                nohup $DOMAIN_HOME_M/bin/startNodeManager.sh >>$log_file 2>&1 &

            fi

        else

            local nm_home=$WLS_HOME/server/bin

            nohup $nm_home/startNodeManager.sh >>$log_file 2>&1 &

        fi

        until (check_ports shared_nm) && (check_ports local_nm); do

            sleep 1

        done

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtgrn}   OK   ${txtrst}]"

        echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

        echo -e "All NodeManagers have been started on $local_alias\n" >>$log_file

    fi

    

    if [[ $control_option == "-r" && $ssh_enabled == "true" ]]; then

        i_name=0; for myhost in ${remote_hosts[@]}; do

            echo -e " - Starting NodeManager on ${remote_aliases[$i_name]}: \t\t\c" | tee -a $log_file

#            echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

            ssh -oStrictHostKeyChecking=no -oCheckHostIP=no $myhost $SHARED_SCRIPTS/"${0##*/}" start_NodeManager -r >/dev/null 2>&1

            if (($?)); then

                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                echo -e "[${txtylw} NOTICE ${txtrst}]"

                echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

                echo -e "Something didn't go as planned; \c" >>$log_file

                echo -e "See $log_file on ${remote_aliases[$i_name]} for more details!\n" >>$log_file

                ((warning_count++))

            else

                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                echo -e "[${txtgrn}   OK   ${txtrst}]"

                echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

                echo -e "NodeManager has been started; \c" >>$log_file

                echo -e "See $log_file on ${remote_aliases[$i_name]} for more details\n" >>$log_file

            fi

        ((i_name++))

        done

    fi

}


stop_nodemanager() # Stops the NodeManagers, applies to WebLogic Server 11g & 12c.

{

    local control_option=$1


    echo -e " - Stopping NodeManager(s) on localhost: \t\t\c" | tee -a $log_file

    echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

    

    if (check_ports local_nm) || (check_ports shared_nm); then

        if [[ -f $DOMAIN_HOME/bin/stopNodeManager.sh ]]; then

            nohup $DOMAIN_HOME/bin/stopNodeManager.sh >>$log_file 2>&1 &

            if [[ ! -z $DOMAIN_HOME_M ]] && [[ $DOMAIN_HOME != $DOMAIN_HOME_M ]] && \

                [[ -f $DOMAIN_HOME_M/bin/stopNodeManager.sh ]]; then

                nohup $DOMAIN_HOME_M/bin/stopNodeManager.sh >>$log_file 2>&1 &

            fi

        else

            if [[ $OSTYPE == *"solaris"* ]]; then

                kill -15 $(netstat -anu | grep $local_nmport | grep "LISTEN" | awk '{print $4}')

                if [[ -n $shared_nmport ]] && [[ $local_nmport != $shared_nmport ]]; then

                    kill -15 $(netstat -anu | grep $shared_nmport | grep "LISTEN" | awk '{print $4}')

                fi

            elif [[ $OSTYPE == *"linux"* ]]; then

                kill -15 $(lsof -i:$local_nmport | grep "LISTEN" | awk '{print $2}')

                if [[ -n $shared_nmport ]] && [[ $local_nmport != $shared_nmport ]]; then

                    kill -15 $(lsof -i:$shared_nmport | grep "LISTEN" | awk '{print $2}')

                fi

            fi

        fi

        while (check_ports local_nm) || (check_ports shared_nm); do

            sleep 1

        done

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtgrn}   OK   ${txtrst}]"

        echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

        echo -e "NodeManagers have been stopped on $local_alias\n" >>$log_file

    else

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtylw} NOTICE ${txtrst}]"

        echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

        echo -e "No NodeManagers are currently running on localhost!\n" >>$log_file

        ((warning_count++))

    fi

    

    if [[ $control_option == "-r" && $ssh_enabled == "true" ]]; then

        i_name=0; for myhost in ${remote_hosts[@]}; do

            echo -e " - Stopping NodeManager on ${remote_aliases[$i_name]}: \t\t\c" | tee -a $log_file

            echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

            ssh -oStrictHostKeyChecking=no -oCheckHostIP=no $myhost $SHARED_SCRIPTS/"${0##*/}" stop_NodeManager -r >/dev/null 2>&1

            if (($?)); then

                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                echo -e "[${txtylw} NOTICE ${txtrst}]"

                echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

                echo -e "Something didn't go as planned; \c" >>$log_file

                echo -e "See $log_file on ${remote_aliases[$i_name]} for more details!\n" >>$log_file

                ((warning_count++))

            else

                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                echo -e "[${txtgrn}   OK   ${txtrst}]"

                echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

                echo -e "NodeManager has been stopped; \c" >>$log_file

                echo -e "See $log_file on ${remote_aliases[$i_name]} for more details\n" >>$log_file

            fi

        ((i_name++))

        done

    fi 

}


start_opmn() # Starts all Oracle HTTP Server instances.

{

    local control_option=$1

    local running_count=0

    local my_script=$my_scripts/startOHS.py

    

    oIFS=$IFS

    IFS=':'

    opmn_paths=($OPMN_HOMES)

    IFS=""

    opmn_paths=(${opmn_paths[@]})

    IFS=$oIFS

    

    echo -e " - Starting OPMN on localhost: \t\t\t\t\c" | tee -a $log_file

    echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

    

    if [[ -f  $DOMAIN_HOME_M/bin/startComponent.sh ]]; then

        if (check_ports local_nm); then 

            echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

            echo -e "Starting OHS component for $s_hostname" >>$log_file

            $MW_HOME/oracle_common/common/bin/wlst.sh $my_script \

                $DOMAIN_NAME $local_nmport $local_alias \

                    $username $password $connect_type $s_hostname >>$log_file 2>&1

            if (($?)); then

                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                echo -e "[${txtred} FAILED ${txtrst}]"

                echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

                echo -e "${my_script##*/} failed for $s_hostname!\n" >>$log_file

                ((error_count++))

            else

                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                echo -e "[${txtgrn}   OK   ${txtrst}]"

                echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

                echo -e "OHS has been started on $local_alias\n" >>$log_file

            fi

        else

                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                echo -e "[${txtred} FAILED ${txtrst}]"

                echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

                echo -e "NodeManager is not running on \c" >>$log_file

                echo -e "$local_alias:$local_nmport!\n" >>$log_file

                ((error_count++))

        fi         

        if [[ $control_option == "-r" ]]; then

            echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

            echo -e "Remote execution will be done via WLST --not SSH\n" >>$log_file

            control_option="-l"

        fi

    elif ((${#opmn_paths[@]} > 0)); then         

        for instance in ${opmn_paths[@]}; do

            if [[ -d "$instance/bin" && $instance != "/" ]]; then

                echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

                echo -e "Instance home $instance" >>$log_file

                if (($($instance/bin/opmnctl status | grep -c "Alive") > 0)); then

                    echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

                    echo -e "$instance is already running!" >>$log_file

                    ((warning_count++))

                else

                    $instance/bin/opmnctl startall >>$log_file 2>&1

                    if (($($instance/bin/opmnctl status | grep -c "Alive") > 0)); then

                        ((running_count++))

                    else

                        ((running_count--))

                    fi

                fi

            else

                echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

                echo -e "Skipping invalid instance $instance!" >>$log_file

                ((warning_count++))

            fi

        done

        if [[ $running_count ==  0 ]]; then

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtylw} NOTICE ${txtrst}]"

            echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

            echo -e "All known ias-instances are already running!" >>$log_file

            ((warning_count++))

        elif [[ $running_count < ${#opmn_paths[@]} ]]; then

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtred} FAILED ${txtrst}]"

            echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

            echo -e "Not all known ias-instances are running!\n" >>$log_file

            ((error_count++))

        else

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtgrn}   OK   ${txtrst}]"

            echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

            echo -e "OPMN has been started on $local_alias\n" >>$log_file

        fi    

    else

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtred} FAILED ${txtrst}]"

        echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

        echo -e "Not able to find components in environment!\n" >>$log_file

        ((error_count++))

    fi

    

    if [[ $control_option == "-r" && $ssh_enabled == "true" ]]; then

        i_name=0; for myhost in ${remote_hosts[@]}; do

            echo -e " - Starting OPMN on ${remote_aliases[$i_name]}: \t\t\t\c" | tee -a $log_file

            echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

            ssh -oStrictHostKeyChecking=no -oCheckHostIP=no $myhost $SHARED_SCRIPTS/"${0##*/}" start_OPMN -r >/dev/null 2>&1

            if (($?)); then

                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                echo -e "[${txtylw} NOTICE ${txtrst}]"

                echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

                echo -e "Something didn't go as planned; \c" >>$log_file

                echo -e "See $log_file on ${remote_aliases[$i_name]} for more details!\n" >>$log_file

                ((warning_count++))

            else

                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                echo -e "[${txtgrn}   OK   ${txtrst}]"

                echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

                echo -e "OPMN has been started; \c" >>$log_file

                echo -e "See $log_file on ${remote_aliases[$i_name]} for more details\n" >>$log_file

            fi

        ((i_name++))

        done

    elif [[ $control_option == "-l" ]]; then

        i_name=0; for myhost in ${remote_hosts[@]}; do

            echo -e " - Starting OPMN on ${remote_aliases[$i_name]}: \t\t\t\c" | tee -a $log_file

            echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

            myhost_ip=$(getent hosts $myhost | awk '{print $1}')

            my_nmport=$(grep $myhost $temp_machine_file | awk -F ":" '{print $2}')

            bash -c "cat </dev/null >/dev/tcp/$myhost_ip/$my_nmport" >/dev/null 2>&1

            if (($?)); then

                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                echo -e "[${txtred} FAILED ${txtrst}]"

                echo -e "\n[CRITICAL] ${FUNCNAME[1]}(): \c" >>$log_file

                echo -e "NodeManager is not running on \c" >>$log_file

                echo -e "$myhost:$my_nmport!\n" >>$log_file

                ((error_count++))

            else

                $MW_HOME/oracle_common/common/bin/wlst.sh $my_script \

                    $DOMAIN_NAME $my_nmport $myhost \

                        $username $password $connect_type ${remote_aliases[$i_name]} >>$log_file 2>&1

                if (($?)); then

                    echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                    echo -e "[${txtred} FAILED ${txtrst}]"

                    echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

                    echo -e "${my_script##*/} failed for ${remote_aliases[$i_name]}!\n" >>$log_file

                    ((error_count++))

                else

                    echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                    echo -e "[${txtgrn}   OK   ${txtrst}]"

                    echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

                    echo -e "OHS has been started on ${remote_aliases[$i_name]}\n" >>$log_file

                fi

            fi

        ((i_name++))

        done

    fi

}


stop_opmn() # Stops all Oracle HTTP Server instances.

{

    local control_option=$1

    local running_count=0

    local my_script=$my_scripts/stopOHS.py

    

    oIFS=$IFS

    IFS=':'

    opmn_paths=($OPMN_HOMES)

    IFS=""

    opmn_paths=(${opmn_paths[@]})

    IFS=$oIFS

    

    echo -e " - Stopping OPMN on localhost: \t\t\t\t\c" | tee -a $log_file

    echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

    

    if [[ -f  $DOMAIN_HOME_M/bin/stopComponent.sh ]]; then

        if (check_ports local_nm); then

            echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

            echo -e "Stopping OHS component for $s_hostname" >>$log_file

            $MW_HOME/oracle_common/common/bin/wlst.sh $my_script \

                $DOMAIN_NAME $local_nmport $local_alias \

                    $username $password $connect_type $s_hostname >>$log_file 2>&1

            if (($?)); then

                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                echo -e "[${txtred} FAILED ${txtrst}]"

                echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

                echo -e "${my_script##*/} failed for $s_hostname!\n" >>$log_file

                ((error_count++))

            else

                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                echo -e "[${txtgrn}   OK   ${txtrst}]"

                echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

                echo -e "OHS has been stopped on $local_alias\n" >>$log_file

            fi

        else

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtred} FAILED ${txtrst}]"

            echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

            echo -e "NodeManager is not running on \c" >>$log_file

            echo -e "$local_alias:$local_nmport!\n" >>$log_file

            ((error_count++))

        fi

        if [[ $control_option == "-r" ]]; then

            echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

            echo -e "Remote execution will be done via WLST --not SSH\n" >>$log_file

            control_option="-l"

        fi

    elif ((${#opmn_paths[@]} > 0)); then         

        for instance in ${opmn_paths[@]}; do

            if [[ -d "$instance/bin" && $instance != "/" ]]; then

                echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

                echo -e "Instance home $instance" >>$log_file

                if (($($instance/bin/opmnctl status | grep -c "Alive") > 0)); then

                    instance_pid_list=($($instance/bin/opmnctl status | grep "Alive" | awk '{print $5}'))

                    $instance/bin/opmnctl stopall >>$log_file 2>&1

                    for instance_pid in ${instance_pid_list[@]}; do

                        if (kill -0 $instance_pid 2>/dev/null); then

                            kill -9 $instance_pid

                            ((running_count--))

                        else

                            ((running_count++))

                        fi

                    done

                else

                    echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

                    echo -e "$instance is not currently running!" >>$log_file

                    ((warning_count++))

                fi

            else

                echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

                echo -e "Skipping invalid instance $instance!" >>$log_file

                ((warning_count++))

            fi

        done

        if [[ $running_count == 0 ]]; then

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtylw} NOTICE ${txtrst}]"

            echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

            echo -e "All known ias-instances are already stopped!" >>$log_file

            ((warning_count++))

        elif [[ $running_count < ${#opmn_paths[@]} ]]; then

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtylw} NOTICE ${txtrst}]"

            echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

            echo -e "Had to forcefully kill ias-instance processes!\n" >>$log_file

            ((warning_count++))

        else

            echo -e "\b\b\b\b\b\b\b\b\b\b\c"

            echo -e "[${txtgrn}   OK   ${txtrst}]"

            echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

            echo -e "OPMN has been stopped on $local_alias\n" >>$log_file

        fi

    else

        echo -e "\b\b\b\b\b\b\b\b\b\b\c"

        echo -e "[${txtred} FAILED ${txtrst}]"

        echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

        echo -e "Not able to find components in environment!\n" >>$log_file

        ((error_count++))

    fi

    

    if [[ $control_option == "-r" && $ssh_enabled == "true" ]]; then

        i_name=0; for myhost in ${remote_hosts[@]}; do

            echo -e " - Stopping OPMN on ${remote_aliases[$i_name]}: \t\t\t\c" | tee -a $log_file

            echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

            ssh -oStrictHostKeyChecking=no -oCheckHostIP=no $myhost $SHARED_SCRIPTS/"${0##*/}" stop_OPMN -r >/dev/null 2>&1

            if (($?)); then

                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                echo -e "[${txtylw} NOTICE ${txtrst}]"

                echo -e "\n[WARNING] $FUNCNAME(): \c" >>$log_file

                echo -e "Something didn't go as planned; \c" >>$log_file

                echo -e "See $log_file on ${remote_aliases[$i_name]} for more details!\n" >>$log_file

                ((warning_count++))

            else

                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                echo -e "[${txtgrn}   OK   ${txtrst}]"

                echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

                echo -e "OPMN has been stopped on $myhost; \c" >>$log_file

                echo -e "See $log_file on ${remote_aliases[$i_name]} for more details\n" >>$log_file

            fi

        ((i_name++))

        done

    elif [[ $control_option == "-l" ]]; then

        i_name=0; for myhost in ${remote_hosts[@]}; do

            echo -e " - Stopping OPMN on ${remote_aliases[$i_name]}: \t\t\t\c" | tee -a $log_file

            echo -e "${txtdim}${txtflsh}...WAITING${txtrst}\c"

            myhost_ip=$(getent hosts $myhost | awk '{print $1}')

            my_nmport=$(grep $myhost $temp_machine_file | awk -F ":" '{print $2}')

            bash -c "cat </dev/null >/dev/tcp/$myhost_ip/$my_nmport" >/dev/null 2>&1

            if (($?)); then

                echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                echo -e "[${txtred} FAILED ${txtrst}]"

                echo -e "\n[CRITICAL] ${FUNCNAME[1]}(): \c" >>$log_file

                echo -e "NodeManager is not running on \c" >>$log_file

                echo -e "${remote_aliases[$i_name]}:$my_nmport!\n" >>$log_file

                ((error_count++))

            else

                $MW_HOME/oracle_common/common/bin/wlst.sh $my_script \

                    $DOMAIN_NAME $my_nmport $myhost \

                        $username $password $connect_type ${remote_aliases[$i_name]} >>$log_file 2>&1

                if (($?)); then

                    echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                    echo -e "[${txtred} FAILED ${txtrst}]"

                    echo -e "\n[CRITICAL] $FUNCNAME(): \c" >>$log_file

                    echo -e "$${my_script##*/} failed for ${remote_aliases[$i_name]}!\n" >>$log_file

                    ((error_count++))

                else

                    echo -e "\b\b\b\b\b\b\b\b\b\b\c"

                    echo -e "[${txtgrn}   OK   ${txtrst}]"

                    echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

                    echo -e "OHS has been stopped on ${remote_aliases[$i_name]}\n" >>$log_file

                fi

            fi

        ((i_name++))

        done

    fi

}


fmw_srvctl() # Principal wrapper function --all available commands: 

{    

    case $control_command in

        start_Domain)

            get_context

            is_adminserver

            check_ssh

            start_nodemanager -r

            start_adminserver

            if [[ $instance_type == *"oid_domain"* ]]; then

                start_opmn -r

                start_managedservers

            elif [[ $instance_type == *"oam_domain"* ]]; then

                start_managedservers

                start_opmn -r

            else

                start_opmn -r

                start_managedservers

            fi

            if [[ $control_session != "-m" ]]; then    

                check_health domain

            fi    

            ;;

        stop_Domain)

            get_context

            is_adminserver

            check_ssh

            stop_managedservers

            stop_adminserver

            stop_opmn -r

            stop_nodemanager -r

            ;;

        restart_Domain)

            get_context

            is_adminserver

            check_ssh

            stop_managedservers

            stop_adminserver

            stop_opmn -r

            stop_nodemanager -r

            start_nodemanager -r

            start_adminserver

            if [[ $instance_type == *"oid_domain"* ]]; then

                start_opmn -r

                start_managedservers

            elif [[ $instance_type == *"oam_domain"* ]]; then

                start_managedservers

                start_opmn -r

            else

                start_opmn -r

                start_managedservers

            fi

            if [[ $control_session != "-m" ]]; then    

                check_health domain

            fi

            ;;

        status_Domain)

            get_context

            is_adminserver

#            check_ssh

            check_health domain

            ;;

        start_AdminServer)

            start_adminserver

            ;;

        stop_AdminServer)

            stop_adminserver

            ;;

        restart_AdminServer)

            stop_adminserver

            start_adminserver

            ;;

        status_AdminServer)

            check_health adminserver

            ;;

        start_ManagedServers)

            start_managedservers

            ;;

        stop_ManagedServers)

            stop_managedservers

            ;;

        restart_ManagedServers)

            stop_managedservers

            start_managedservers

            ;;

        status_ManagedServers)

            check_health managedservers

            ;;

        start_NodeManager)

            start_nodemanager

            ;;

        stop_NodeManager)

            stop_nodemanager

            ;;

        restart_NodeManager)

            stop_nodemanager

            start_nodemanager

            ;;

        status_NodeManager)

            check_health nodemanager

            ;;

        start_OPMN)

            start_opmn

            ;;

        stop_OPMN)

            stop_opmn

            ;;

        restart_OPMN)

            stop_opmn

            start_opmn

            ;;

        status_OPMN)

            check_health opmn

            ;;

        *)

            echo -e "\nInvalid option(s)"

            show_usage

    esac

}


get_my_name() # Who you are logged in as?

{

    # For logging purposes record who is associated with stdin, daemon, or odcagent.

    if [[ -n $(logname) ]]; then

        user_id=$(logname)

    elif [[ -n $(who is there | awk '{print $1}') ]]; then

        user_id=$(who commands me | awk '{print $1}')

    else

        user_id=$USER

    fi

}


phone_home() # E-mails OMCS/FMW Team when invoked, as a counter mechanism.

{    

    local exit_status=$1

    

    #to_address="omcs_wlsautostart_events_grp@oracle.com"

    if [[ $source_dir == *"prod"* ]]; then

        to_address="-c david.sorgi@oracle.com"

    else

        to_address="david.sorgi@oracle.com"

    fi

    

    if [[ $control_session == "-d" ]]; then

        session_type="daemon init.d script"

        user_id="$session_type"

    elif [[ $control_session == "-e" ]]; then

        session_type="CA (EM) triggered event"

        user_id="$session_type"

     elif [[ $control_session == "-m" ]]; then

        session_type="MCollective daemon"

        user_id="$session_type"

    fi

    

    case $exit_status in

        Error)

            subject="[${0##*/}] $control_command ran with errors on $instance_name"

            message_body="$my_version ($rel_v_date) called from: $source_dir\n\n"

            message_body+="OneCommand invoked by $user_id for $instance_type failed on $(uname): $f_hostname"

            message_body+="\n\n$debug_message"

            ;;

        Success)

            subject="[${0##*/}] $control_command ran successfully on $instance_name"

            message_body="$my_version ($rel_v_date) called from: $source_dir\n\n"

            message_body+="OneCommand invoked by $user_id for $instance_type succeeded on $(uname): $f_hostname"

            message_body+="\n\n$debug_message"

            ;;

        Terminated)

            subject="[${0##*/}] $control_command was aborted on $instance_name"

            message_body="$my_version ($rel_v_date) called from: $source_dir\n\n"

            message_body+="OneCommand invoked by $user_id for $instance_type terminated on $(uname): $f_hostname"

            message_body+="\n\n$debug_message"

            ;;

        Warning)

            subject="[${0##*/}] $control_command ran with warnings on $instance_name"

            message_body="$my_version ($rel_v_date) called from: $source_dir\n\n"

            message_body+="OneCommand invoked by $user_id for $instance_type succeeded on $(uname): $f_hostname"

            message_body+="\n\n$debug_message"

    esac

    

    if [[ $control_session != "-r" ]]; then

        echo -e "$message_body" | mailx -s "$subject" $to_address

    fi

}


set_exit() # Report exit status message(s) before terminating.

{

    local return_status=$1

    

    end_time=$(date +%s)

    run_time=$(($end_time - $start_time))

    

    if [[ -w $log_file ]]; then

        echo -e "\n[INFO] $FUNCNAME(): \c" >>$log_file

        echo -e "Wrapping up session!\n" >>$log_file

    fi

    

    if [[ -z $debug_message ]]; then

        if (($error_count > 0)) || (($warning_count > 0)); then

            debug_message=$(tac $log_file \

                | awk '/ Wrapping up /{p=1; next} p && / Session Start /{exit} p' \

                    | grep -E "\[CRITICAL\]|\[WARNING\]" | tac)

        elif [[ $health_check == "passed" ]]; then

            debug_message=$(tac $log_file \

                    | awk '/ Wrapping up /{p=1; next} p && / Session Start /{exit} p' \

                        | grep "\[INFO\] check_health" | tac)

        fi

    fi

    

    if (($error_count > 0)); then

        return_status=1

    elif (($warning_count > 0)); then

        return_status=246

    fi

        

    case $return_status in

        0)

            phone_home "Success"

            ;;

        1)

            phone_home "Error"

            ;;

        2)

            log_file='/dev/null'

            ;;

        126)

            log_file='/dev/null'

            phone_home "Error"

            ;;

        246)

            phone_home "Warning"

            ;;

        *)

            return_status=130

            debug_message+="[CRITICAL] ${FUNCNAME[1]}(): "

            debug_message+="User must've pressed Ctrl+C "

            debug_message+="or process was killed by some other force!"

            phone_home "Terminated"

    esac

    

    if [[ -n $debug_message && $return_status != 0 ]]; then

        echo -e "\n$debug_message"

    fi 

    

###    if [[ $return_status != 2 ]]; then

#        echo -e "\nTotal run time for $instance_type: \c" | tee -a $log_file

#        echo -e "$(($run_time / 60)) minutes and \c" | tee -a $log_file

#        echo -e "$(($run_time % 60)) seconds." | tee -a $log_file

#        echo -e "Instance: $instance_name => Host: $f_hostname\n" | tee -a $log_file

#        if [[ $return_status != 126 ]]; then

#            echo -e "${0##*/} may have written additional warning messages."

#            echo -e "For more information, please check: ${txtunl}$log_file${txtrst}\n"

#        fi

#        echo -e "$(date) :: ${0##*/} is exiting with status \c" | tee -a $log_file

#        echo -e "$return_status\n" | tee -a $log_file

#        echo -e "========== OMCS OneCommand Session End ===========\n" >>$log_file

##    fi

    

    # Prompt Control: For interactive shells, give the cursor back (show).

###    if [[ -t 0 || -p /dev/stdin ]]; then

  #     tput cnorm || tput ve >/dev/null 2>&1

 ##   fi

    

    exit $return_status

}


# Prompt Control: For interactive shells, take the cursor away (hide).

if [[ -t 0 || -p /dev/stdin ]]; then

  tput civis || tput vi >/dev/null 2>&1

fi


# Trap Ctrl+C or similar process termination request.

trap set_exit SIGINT SIGTERM


# This in Main:

if [[ -z $2 || $2 == "-d" || $2 == "-e" || $2 == "-m" || $2 == "-r" ]]; then

    case $1 in

        -h|--help|-help|--?|-?|"")

            show_usage

            ;;

        *)

##            hello

            unset_env

            get_my_name

            get_my_version

            set_wls_properties

            set_logging

            fmw_srvctl $1

    esac

else

    echo -e "\nInvalid option(s)"

    show_usage

fi


set_exit 0


Google, Mozilla, and Apple choosing to no longer support Entrust as a publicly trusted certificate authority

Google, Mozilla, and Apple have all decided to stop trusting Entrust’s publicly issued certificates after specific cutoff dates , due to lon...