Shell Scripts For Oracle Database and e Business Suite
Shell Scripts For Oracle Database and e Business Suite
Akhash Ramnath
Doyensys Pvt Ltd
These scripts work in a unique way with a common env file that has
all the necessary information for the scripts to work. This helps us to
manage operation of Shell Scripts from a centralized env file.
These Shell Scripts sends alerts to the respective team only when
there is an issue and maintains a log for reference.
Having a centralized env file for Shell Scripts will help us reduce the
effort in making any modifications in the future without disturbing all
scripts.
In order to easily maintain and manage the Shell Scripts performing the following will help us a lot in
many aspects,
A. Create & Maintain a common env file for the shell script and include all important variables required
for the scripts in the common env file
B. Decrypt the passwords called/used in the Shell Scripts and maintain it in a hidden file
C. Maintain a log of every important tasks for reference,forecasting, etc.
Pre req,
For the sake of this document lets assume our locations as follows,
Using the user credentials(Username/Password) in the Shell Scripts are very common.
Saving the Username & Password in a common hidden file and calling them in the script is a simple
method. It allows the Administrator to make sure that the password is unknown/hidden in all the Shell
Scripts and if there is a change in the credentials in the future we don't have to modify the credentials
in each and every script, just changing it in the common hidden file will be enough.
We could also encrypt/decrypt the passwords so that the password is unknown to the persons who
are not DBA’s. Here i have Incorporated a simple built in OS Utility openssl to encrypt/decrypt the
passwords.
For example,
$ cat /home/oracle/MONITOR/ENV/.secpass
APPSPWD=U2FsdGVkX18eXjViNN+HczNVqMHCfNqvHd+rneeejuo=; export APPSPWD
SYSPWD=U2FsdGVkX18eXjViNN+HczNVqMHCfNqvHd+rneeejuo=; export SYSPWD
SYSTPWD=U2FsdGVkX18eXjViNN+HczNVqMHCfNqvHd+rneeejuo=; export SYSTPWD
I have encrypted the APPS, SYS, SYSTEM user password using openssl and have saved the values in a
variable. I will call the respective variable in the Shell Scripts wherever possible.Prepare a file with
respective password for your environment and place them in all the db and application servers.
All our scripts will depend on the common file and the common env file has the typical variables/values
a shell scripts would require. Our scripts will send alerts only if there is an issue, and the will come to us
in clear HTML format with the help of a css script(markup.sql) that is called in the Shell Scripts.
markup.sql
All the logs will be present in the LOG_HOME. Place this markup.sql file in the $SCRIPTS_HOME and call
it where ever required.
Now that we have created the Common env file and the file to store the password, we shall go ahead
and write Shell Scripts to Monitor our EBS and Database system.
This is a simple script to check the availability of the Database Instance. The database
availability log is stored in dbstatus_hist.log file. Alert will be sent to the users in the
distribution list only if the database is not available.
if cat $lsnr_statuslog2|grep -i "The command completed successfully" > /dev/null && tnsping
$ORACLE_SID > /dev/null
then
{
echo "$ORACLE_SID listener is Up and Running - $dateis" >> $lsnr_statuslog
}
else
{
echo "$ORACLE_SID listener is Down - $dateis" >> $lsnr_statuslog
echo -e "Team,\n\n$ORACLE_SID Listener $ORACLE_SID might be Down on `hostname`, please
cheack ASAP!!!\n" > $mail_message
cat $lsnr_statuslog2 >> $mail_message
echo -e "\nRefer to script logfiles $lsnr_statuslog and $lsnr_statuslog2." >> $mail_message
echo -e "Thanks,\nDBA Team" >> $mail_message
mailx -s "CRITICAL:Alarm:$ORACLE_SID listener is Down - $dateis" $maillist < $mail_message
}
fi
This is a simple script to check the availability of the Database Listener. The database
availability log is stored in lsnr_statuslog_hist.log file. Alert will be sent to the users in
the distribution list only if the listener is not available.
if [ $cnt -eq 0 ]
then
cat $tbsrpt_rep|grep -v "selected."|mutt -e 'set content_type=text/html' -s 'Critical - Tablespaces with less space
in '$ORACLE_SID' on '$dateis'' $maillist
fi
The script will check for tablespace’s used space and if the used space has crossed
95% the users in the distribution list will get alerts.
This script will check for any new ORA- errors in the database alert log file and send
an alert to the users in the distribution list.Please source the alert log of the database
in alert_log variable.
sqlplus -silent -S -M "HTML ON TABLE 'BORDER="2"'" "/as sysdba" << EOF > $blocking_sess_det
@$SCRIPTS_HOME/markup.sql
set feedback on;
prompt <i>Team,</i><br>
prompt <i>There are blocking sessions in $ORACLE_SID on `hostname`,pls check ASAP!!!</i><br>
@$SCRIPTS_HOME/block.sql
prompt <i>Thanks,</i>
prompt <i>DBA Team</i>
set markup html off;
quit;
EOF
if [ $cnt -eq 0 ]
then
#cat $blocking_sess_det|grep -v "selected."|mailx -s "$(echo -e "Blocking session in $ORACLE_SID -
$dateis\nContent-Type: text/html")" $maillist
cat $blocking_sess_det|grep -v "selected."|mutt -e 'set content_type=text/html' -s 'Blocking session
in '$ORACLE_SID' - '$dateis'' $maillist
fi
This script will check for blocking session in the database, kindly place the block.sql
file under $SCRIPTS_HOME directory.
block.sql
Script sends out an alert to the users in distribution list if there are any blocking
sessions.
Please create a directory RMAN under $LOGS_HOME and under RMAN directory
create two directories DB and ARC for db and archive log backup logfiles respectively.
if [ $rman_err_cnt -gt 0 ]
then
echo "RMAN DB Full backup has failed/have errors at $dateis in $ORACLE_SID" >>
$rman_dbfull_log_hist
echo -e "Team,\n\nDB Full backup has completed with errors or have failed in $ORACLE_SID on
`hostname`.\n" > $mail_message
echo -e "Please find the log as follows,\n" >> $mail_message
cat $rman_dbfull_log >> $mail_message
echo -e "\nRefer to script logfiles $rman_dbfull_log and $rman_dbfull_log_hist.\n" >>
$mail_message
echo -e "Thanks,\nDBA Team" >> $mail_message
mailx -s "$ORACLE_SID DB Full Backup has failed - $dateis!!! " $maillist < $mail_message
else
echo "RMAN DB Full backup has completed successfully at $dateis in $ORACLE_SID" >>
$rman_dbfull_log_hist
fi
backup_db.rman
Place this file under $SCRIPTS_HOME, the script will take a full backup of the
database and check if the backup has got completed successfully. If there are any
errors in the backup, an alert will be sent by the script to the users.
The script also maintains a log of the backup status every time it is executed in the
$LOGS_HOME directory.
10
if [ $rman_err_cnt -gt 0 ]
then
echo "RMAN DB Incremental backup has failed/have errors at $dateis in $ORACLE_SID" >>
$rman_dbincr_log_hist
echo -e "Team,\n\nDB Incremental backup has completed with errors or have failed in $ORACLE_SID on
`hostname`.\n" > $mail_message
echo -e "Please find the log as follows,\n" >> $mail_message
cat $rman_dbincr_log >> $mail_message
echo -e "\nRefer to script logfiles $rman_dbincr_log and $rman_dbincr_log_hist.\n" >> $mail_message
echo -e "Thanks,\nDBA Team" >> $mail_message
mailx -s "$ORACLE_SID DB Incremental Backup has failed - $dateis!!! " $maillist < $mail_message
else
echo "RMAN DB Incremental backup has completed successIncrementaly at $dateis in $ORACLE_SID" >>
$rman_dbincr_log_hist
fi
backup_db_incr.r
man
Place this file under $SCRIPTS_HOME, the script will take an Incremental backup of
the database and check if the backup has got completed successfully. If there are any
errors in the backup, an alert will be sent by the script to the users.
The script also maintains a log of the backup status every time it is executed in the
$LOGS_HOME directory.
11
if [ $rman_err_cnt -gt 0 ]
then
echo "RMAN Archivelogs backup has failed/have errors at $dateis in $ORACLE_SID" >>
$rman_arc_log_hist
echo -e "Team,\n\nArchivelog backup has completed with errors or have failed in $ORACLE_SID on
`hostname`.\n" > $mail_message
echo -e "Please find the log as follows,\n" >> $mail_message
cat $rman_arc_log >> $mail_message
echo -e "\nRefer to script logfiles $rman_arc_log and $rman_arc_log_hist.\n" >> $mail_message
echo -e "Thanks,\nDBA Team" >> $mail_message
mailx -s "$ORACLE_SID Archivelog Backup has failed - $dateis!!! " $maillist < $mail_message
else
echo "RMAN Archivelogs backup completed successfully at $dateis in $ORACLE_SID" >>
$rman_arc_log_hist
fi
backup_arch.rma
n
Place this file under $SCRIPTS_HOME, the script will take a backup of the Archivelogs
of the database and check if the backup has got completed successfully. If there are
any errors in the backup, an alert will be sent by the script to the users.
The script also maintains a log of the backup status every time it is executed in the
$LOGS_HOME directory.
12
This Script will delete archive logs older than 2 days and also check for expired
archive logs and remove them if any.
13
This is a bonus script that does a basic sanity check to your database and sends a
report to the users. Please create a directory “dbaallmonitor” under $LOGS_HOME.
monitor_log=$LOGS_HOME/dballmonitor/dballmonitor_"$ORACLE_SID"_`date +%d%b%y_%H%M`.html;
export monitor_log
dateis=`date +"%a"" ""%d"/"%b"/"%Y"" ""%H":"%M":"%S"`; export dateis
mountpnt_log=$LOGS_HOME/mountpnt_log.log; export mountpnt_log
mail_message=$MAILLOG_HOME/dballmonitormail.log; export mail_message
sqlplus -silent -S -M "HTML ON TABLE 'BORDER="2"'" "/as sysdba" << EOF >> $monitor_log
@$SCRIPTS_HOME/markup.sql
set feedback off;
alter session set nls_numeric_characters='.''' nls_date_format='Day DD. Month, YYYY';
prompt <i>Here is the complete Database health check report per &_DATE</i><br>
@$SCRIPTS_HOME/db_det.sql
set markup html off;
quit;
EOF
sqlplus -silent -S -M "HTML ON TABLE 'BORDER="2"'" "/as sysdba" << EOF >> $monitor_log
set feedback off;
@$SCRIPTS_HOME/markup.sql
@$SCRIPTS_HOME/db_det2.sql
set markup html off;
quit;
EOF
14
## mail information
cat $monitor_log|mutt -e 'set content_type=text/html' -s "Complete Health Check report for
$ORACLE_SID Database on $dateis" $maillist
db_det.sql db_det2.sql
Place the above files under $SCRIPTS_HOME. This scripts does a basic sanity check to
the database and sends us a report on the availability of the DB instance, listener, DB
Size, Tablespace Usage report, Invalid Object list, Mount Point space usage.
15
if cat $temp_app_monlog|grep -i "oacore"|grep -i alive > /dev/null && [ "$oacore_cnt" -eq '4' ]
then
{
echo "Oacore Services are Up" >> $app_monlog2
}
else
{
echo "Oacore Services are Down !!!!" >> $app_monlog2
}
fi
if cat $temp_app_monlog|grep -i "forms"|grep -i alive > /dev/null && [ "$forms_cnt" -eq '2' ]
then
{
echo "Forms Services are Up" >> $app_monlog2
}
else
{
echo "Forms Services are Down !!!!" >> $app_monlog2
}
fi
16
This script checks the availability of EBS services like http, oacore, oafm, forms etc
and sends to an alert to the distribution list if any services are down/not reachable. If
you have more than one forms, oacore services modify the count in the if condition
for the respective service.
17
if cat $conc_monlog1|grep -i "Internal Concurrent Manager is Active" > /dev/null && [ "$conc_sermon" -gt '40' ]
then
{
echo "Concurrents Managers are up and running fine - $dateis" >> $conc_monlog
echo "FNDLIBR count is - $conc_sermon - $dateis" >> $conc_monlog
}
else
{
echo "Concurrents Managers might be Down - $dateis" >> $conc_monlog
echo "FNDLIBR count is - $conc_sermon - $dateis" >> $conc_monlog
echo -e "Team,\n\nConcurrent Manager services of $TWO_TASK might be Down on `hostname`, please cheack
ASAP!!!\n" > $mail_log
cat $conc_monlog1 >>$mail_log
echo "FNDLIBR count is - $conc_sermon" >>$mail_log
echo -e "\nRefer to script logfiles $conc_monlog1 and $conc_monlog" >> $mail_log
echo -e "\nThanks,\nDBA Team" >> $mail_log
cat $mail_log|mailx -s "Critical: Alarm - Concurrent Manager services of $TWO_TASK might be Down!!! - $dateis"
$maillist
}
fi
Script to check the concurrent manager status, script will send out an alert to the
users if the concurrent managers are down/unavailable.Also we shall set a threshold
for number of concurrent managers running in a node, the script will alert the users if
there is any reduction in the no of concurrent managers running.
18
sqlplus -silent -S -M "HTML ON TABLE 'BORDER="2"'" "apps/$watw" << EOF > $longrun_out
@$SCRIPTS_HOME/markup.sql
set pages 300;
prompt <i>Team,</i><br>
prompt <i>Please find the long running Concurrent Programs in $TWO_TASK as follows,</i><br>
SELECT fcp.user_concurrent_program_name "Concurrent Program Name"
,fcr.request_id "Request Id"
,ROUND (((SYSDATE - fcr.actual_start_date) * 60 * 24), 2) "Runtime in Mins"
,TO_CHAR (fcr.actual_start_date, 'DD-MON-YYYY HH24:MI:SS') "Actual Start Date"
,DECODE (fcr.status_code, 'R', fcr.status_code) "Status"
,fcr.argument_text "Parameters"
FROM apps.fnd_concurrent_requests fcr
,apps.fnd_user fu
,apps.fnd_responsibility_tl fr
,apps.fnd_concurrent_programs_tl fcp
WHERE fcr.status_code LIKE 'R'
AND fu.user_id = fcr.requested_by
AND fr.responsibility_id = fcr.responsibility_id
AND fcr.concurrent_program_id = fcp.concurrent_program_id
AND fcr.program_application_id = fcp.application_id
AND ROUND (((SYSDATE - fcr.actual_start_date) * 60 * 24), 2) > 120
ORDER BY 3 desc;
prompt <i>Thanks,</i><br>
prompt <i>DBA Team</i><br>
set markup html off;
quit;
EOF
if [ $ct -eq 0 ]
then
cat $longrun_out|grep -v "selected."| mutt -e 'set content_type=text/html' -s "Long running Concurrent request in
$TWO_TASK on $dateis" $maillist
fi
Script to check for long running concurrent request, threshold is set to 120 mins.
The script will sent out alerts with the details of the concurrent request.
19
Script checks the status of the Workflow notification Mailer and sends out an alert to
the users if the mailer services are down.
20
Forms runaway processes are frmweb processes that doesn't have a valid
background db session, these are unwanted zombie processes that consumes the
server resources.
#Script to Kill runaway Form processes
. /home/applmgr/MONITOR/ENV/scr_envcall_apps
proc_id_list=`ps -ef|grep -i frmweb|grep -v grep|awk '{print $2}' > $proc_file`; export proc_id_list
for i in $loop_list
do
sqlplus -s system/$watw << EOF >> $op_log
set serveroutput on;
set feedback off;
declare
prcs_id varchar2(30) :='$i';
lv_n_process varchar2(30);
begin
select distinct process into lv_n_process from
v\$session
where process =prcs_id;
exception
when no_data_found then
dbms_output.put_line('No Database Sessions For Process: '||prcs_id);
end;
/
exit;
EOF
done
21
The script takes a list of frmweb prcesses running in the node and checks if each and
every one of them has a valid db session. If there are no valid db session for a frmweb
process, it is automatically killed by the script.
The script also maintains a log of what processes are getting killed with proper
timestamp.
22
Every EBS environment has few business critical concurrent request that should
complete normal without fail, in case if they fail it is our duty to inform it to the
customer and diagnose why it failed and re submit it. The following scripts monitors
such concurrent requests.
# Script to Check failed concurrent requests
. /home/applmgr/MONITOR/ENV/scr_envcall_apps
failed_conc_req=$LOGS_HOME/failed_conc_req.html;export failed_conc_req
watw=`echo $APPSPWD|openssl enc -aes-128-cbc -a -d -salt -pass pass:asdffdsa`; export watw
dateis=`date +"%a"" ""%d"/"%b"/"%Y"" ""%H":"%M":"%S"`; export dateis
sqlplus -silent -S -M "HTML ON TABLE 'BORDER="2"'" "apps/$watw" << EOF > $failed_conc_req
@$SCRIPTS_HOME/markup.sql
set feedback on;
prompt <i>Team,</i><br>
prompt <i>Following Scheduled Concurrent request's have failed $TWO_TASK - `hostname`,</i><br>
SELECT c.USER_CONCURRENT_PROGRAM_NAME ,To_Char(a.actual_start_date,'DD-MON-YY HH24:MI:SS')
START_DATE,
To_Char(a.actual_completion_date,'DD-MON-YY HH24:MI:SS') END_DATE,
round(((a.actual_completion_date-a.actual_start_date)*24*60*60/60),2) AS Process_time,
a.request_id,a.parent_request_id,To_Char(a.request_date,'DD-MON-YY HH24:MI:SS') REQUEST_DATE,
DECODE(a.PHASE_CODE,'C', 'Completed','I', 'Inactive', 'P', 'Pending', 'R','Running')PHASE_CODE,
DECODE(a.STATUS_CODE,'D','Cancelled', 'E','Error', 'X','Terminated') STATUS_CODE
FROM apps.fnd_concurrent_requests a,
apps.fnd_concurrent_programs b ,
apps.FND_CONCURRENT_PROGRAMS_TL c,
apps.fnd_user d
WHERE a.concurrent_program_id= b.concurrent_program_id AND
b.concurrent_program_id=c.concurrent_program_id AND
a.requested_by =d.user_id AND
trunc(a.actual_completion_date) > trunc(sysdate-1) AND
a.status_code IN ('E','X','D') AND
c.USER_CONCURRENT_PROGRAM_NAME IN
('Name Of Concurrent Request 1','Name Of Concurrent Request 2','Name Of Concurrent Request 3') order by
start_date desc;
prompt <i>Thanks,</i>
prompt <i>DBA Team</i>
set markup html off;
quit;
EOF
if [ $cnt -eq 0 ]
then
cat $failed_conc_req|grep -v "selected."|mutt -e 'set content_type=text/html' -s "Critical
Alert:'$TWO_TASK'-Scheduled Concurrent Request's failed to run" $maillist
fi
Script will sent alert to the users in the distribution list if the mentioned concurrent
request did not complete successfully.
23
scr_log=$LOGS_HOME/cost_manager_status.log;export scr_log
scr_log2=$LOGS_HOME/costmanager.log;export scr_log2
watw=`echo $APPSPWD|openssl enc -aes-128-cbc -a -d -salt -pass pass:asdffdsa`; export watw
dateis=`date +"%a"" ""%d"/"%b"/"%Y"" ""%H":"%M":"%S"`; export dateis
mail_log=$MAILLOG_HOME/mailcostmanagerstatus.log; export mail_log
Script checks if the Cost Manager is up and running and sends out an alert to the
users if the Cost Manager is down/unreachable.
24
monitor_log=$LOGS_HOME/appsallmonitor_"$TWO_TASK"_`date +%d%b%y_%H%M`.html;
export monitor_log
app_bkp_loc=backup_location_mount_point; export app_bkp_loc
app_bkp_log=$LOGS_HOME/appmonitor1_`date +%d%b%y_%H%M`.log; export app_bkp_log
dateis=`date +"%a"" ""%d"/"%b"/"%Y"" ""%H":"%M":"%S"`; export dateis
25
pdnstb_rep=$LOGS_HOME/pdnstb_cnt.log;export pdnstb_rep
mail_log=$MAILLOG_HOME/mailpdnstb.log; export mail_log
watw=`echo $APPSPWD|openssl enc -aes-128-cbc -a -d -salt -pass pass:asdffdsa`; export watw
dateis=`date +"%a"" ""%d"/"%b"/"%Y"" ""%H":"%M":"%S"`; export dateis
Script checks the number of concurrent request in Pending-Standby status and sends
out an alert if the no of conc request in Pending-Standby is abnormal.
26
This script does a basic sanity check on your EBS environment, it checks the
availability of the application services, submits an active user request and also checks
the application directories.Create a directory “appshealthchk” under $LOGS_HOME.
27
if cat $app_monlog2|grep -i "forms"|grep -i alive > /dev/null && [ "$forms_cnt" -eq '2' ]
then
{
echo "<td><b><font size="2" face="verdana" color="green">Forms Services are Up</font></b></td>" >>
$monitor_log
echo "<br>" >> $monitor_log
}
else
{
echo "<td><b><font size="2" face="verdana" color="red">Forms Services are Down !!!!</font></b></td>" >>
$monitor_log
echo "<br>" >> $monitor_log
}
fi
28
29
sleep 10
sqlplus -silent -S -M "HTML ON TABLE 'BORDER="2"'" "apps/$watw" << EOF >> $monitor_log
@$SCRIPTS_HOME/markup.sql
prompt <b><i>Active User Concurrent Request submitted, Request Id is $reqid</i></b>
set lines 200;
set pages 200;
col program for a30;
col user_name for a20;
select a.request_id ,decode(a.phase_code,'C','Completed','R','Running','I','Inactive','P','Pending') Phase,
substr(b.user_concurrent_program_name,1,40) Program, c.user_name
from apps.fnd_concurrent_requests a, apps.fnd_concurrent_programs_tl b, apps.fnd_user c
where a.concurrent_program_id = b.concurrent_program_id
and a.requested_by=c.user_id
and a.request_id='$reqid'
and b.language='US';
set markup html off;
quit;
EOF
## mail information
cat $monitor_log|mutt -e 'set content_type=text/html' -s "Complete Health Check report for $TWO_TASK
Applications on $dateis" $maillist
appdet.sql
30
Thank You
31