Showing posts with label Scripts. Show all posts
Showing posts with label Scripts. Show all posts

Thursday, April 14, 2016

Audit Trail for Custom Table in Oracle Apps - Step By Step


Hi All ...

Here the step by step for Audit Trail for Custom Table in Oracle Apps

1. Register Custom Schema 
Navigate to System Administrator Menu/Security/ORACLE/Register

2. Ensure that Audit on the Application is Enabled
Navigate to System Administrator Menu Security/AuditTrail/Install

The owner of table XX_TABLE  is XX_SCHEMA. Hence query on 
XX_SCHEMA to ensure that Audit is enabled for this Application.


3. Register table,columns and primary key
Here the procedure to register the custom able,columns and primary key in Oracle Applications. Install the procedure on your DB and run the following:

begin
register_table('XX_TABLE','XX_SCHEMA'); /* (table name, table owner) */
commit;
end;

Procedure "register_table":

CREATE OR REPLACE PROCEDURE register_table (
table_name VARCHAR2,
application_short_name VARCHAR2
)
AS
status VARCHAR2 (10);

CURSOR c_columns ( p_table_name all_tab_columns.table_name%TYPE )
IS
SELECT column_name,
data_type,
data_length,
nullable,
ROWNUM,
data_precision,
data_scale
FROM all_tab_columns
WHERE table_name = p_table_name;

CURSOR c_constraints (p_table_name all_tab_columns.table_name%TYPE,
p_application_short_name all_tab_columns.owner%TYPE )
IS
SELECT constraint_name,
table_name,
status
FROM all_constraints
WHERE table_name = p_table_name AND owner = p_application_short_name AND constraint_type = 'P';

CURSOR c_constraint_columns (
p_table_name all_tab_columns.table_name%TYPE,
p_application_short_name all_tab_columns.owner%TYPE
)
IS
SELECT acc.constraint_name,
acc.column_name,
acc.POSITION
FROM all_cons_columns acc, all_constraints ac
WHERE ac.constraint_name = acc.constraint_name
AND ac.table_name = p_table_name
AND ac.constraint_type = 'P'
AND ac.owner = p_application_short_name;
BEGIN

DBMS_OUTPUT.put_line ('Registering Table '|| table_name ||'in application ' || application_short_name);

ad_dd.register_table (p_appl_short_name => application_short_name,
p_tab_name => table_name,
p_tab_type => 'T'
);

FOR r_columns IN c_columns (table_name)
LOOP

DBMS_OUTPUT.put_line ('Registering Column '|| r_columns.column_name);

ad_dd.register_column (p_appl_short_name => application_short_name,
p_tab_name => table_name,
p_col_name => r_columns.column_name,
p_col_seq => r_columns.ROWNUM,
p_col_type => r_columns.data_type,
p_col_width => r_columns.data_length,
p_nullable => r_columns.nullable,
p_translate => 'N',
p_precision => r_columns.data_precision,
p_scale => r_columns.data_scale
);

END LOOP;

FOR r_constraints IN c_constraints (table_name, application_short_name)
LOOP

DBMS_OUTPUT.put_line ('Creating Primary Key Constraint ' || r_constraints.constraint_name);

SELECT DECODE (r_constraints.status,
'ENABLED', 'Y',
'N'
)
INTO status
FROM DUAL;

ad_dd.register_primary_key (p_appl_short_name => application_short_name,
p_key_name => r_constraints.constraint_name,
p_tab_name => table_name,
p_description => 'Primary Key for Table '|| table_name,
p_key_type => 'D',
p_audit_flag => 'Y',
p_enabled_flag => status
);
END LOOP;

FOR r_constraint_columns IN c_constraint_columns (table_name, application_short_name)
LOOP

DBMS_OUTPUT.put_line ( 'Registering Primary Key Column '||
r_constraint_columns.column_name||
' for Constraint '||
r_constraint_columns.constraint_name);

ad_dd.register_primary_key_column (p_appl_short_name => application_short_name,
p_key_name => r_constraint_columns.constraint_name,
p_tab_name => table_name,
p_col_name => r_constraint_columns.column_name,
p_col_sequence => r_constraint_columns.POSITION
);
END LOOP;
END register_table;




4. Create Audit Group
Once you table registered,navigate to System Administrator Menu Security/AuditTrail/Groups 

Application Name: XX Custom Schema
Audit Group: XX Audit
Group State: Enabled

Now, add audit tables to this group[you can add as many tables]
User Table Name: XX_TABLE


5. Run Concurrent program “AuditTrail Update Tables”

This process can be run from System Administrator responsibility. It has no parameter. Running this process will create the Audit tables and the triggers that manage Audit data.


6. Ensure that Audit Tables have been created as expected
SELECT object_name, object_type
FROM all_objects
WHERE object_name LIKE 'XX_TABLE_A%'

OBJECT_NAME                            OBJECT_TYPE
--------------------------                      --------------------------
XX_TABLE_A                               TABLE
XX_TABLE_A                               SYNONYM
XX_TABLE_AC                            TRIGGER
XX_TABLE_AC1                          VIEW
XX_TABLE_AD                            TRIGGER
XX_TABLE_ADP                          PROCEDURE
XX_TABLE_AH                            TRIGGER
XX_TABLE_AI                              TRIGGER
XX_TABLE_AIP                            PROCEDURE
XX_TABLE_AT                             TRIGGER
XX_TABLE_AU                            TRIGGER
XX_TABLE_AUP                          PROCEDURE
XX_TABLE_AV1                           VIEW

Fine, this proves that the concurrent program in Step 5 did its job.
Optionally, you may run concurrent process “AuditTrail Report for Audit Group Validation” to validate the success of Audit Table/Trigger creation.

7. Add further columns for Audit Trail
By default Oracle will Audit Trail on all columns that are a part of first available Unique Index on XX_TABLE.
However further columns can be added to the Audit Trail. Lets say you wish to Audit Trail on Column Meaning too.
Navigate to System Administrator Menu Security/AuditTrail/Tables

You can add additional columns to audit trail and re-execute Step 5.
Please note that adding columns for Audit could have been done immediately after Step 4.

You are DONE...

Usefull notes:
How To Enable Auditing On A Table (Doc ID 1359749.1)
Unable to Enable Audit Trail for Custom Objects (Doc ID 433527.1)


Good Luck ...

Tuesday, July 21, 2015

How to download Oracle Software from Edelivery or Oracle Metalink by script


Hi All ...

Here the step by step guide how to download Oracle software with script.
Many of you already tried to do it from Oracle Edelivery site and know that you need to download one by one and it can take a lot of time. Also there are some scripts that can do it for you , but need to install some plug-ins to google chrome or Mozilla to collect the cookies.

This is the guide that I got from Oracle Support (thanks guys) and hope will make you life a little bit easy.

1. Log-in to http://support.oracle.com 
2. Go to Certifications tab

3. Choose the software,release and platform that  you want to download  and press Search
In my I want to download EBS 12.2.4 installation release for Oracle Linux 5

4. Click on Version on  Number of Releases / Versions column
 5. Choose the release. At this time you can re-choose another release
 6. Select the Product and press Download
 7. Accept the Agreement and press Next
8. Now you will get the all zips that you can download. You can download it one by one or just press on WGET options 
 9. Press on Download.sh to get the scripts and save it. Please pay attention, the script will work only for 8 hours after the creation
10. That's it. Just enter you oracle account password and you can start downloading.


TIP: the release can include alot of file that you will not use, so just remove or remark the WGET line form the script (for example all NLS packages) 

Good Luck ...

Monday, June 29, 2015

How to re-open EXPIRED & LOCKED user with the same password



Hi All ...

Here the fast way to re-open the DB users when it in  EXPIRED & LOCKED status and you don't want to change the password and not remember the old one.

Run the following with "/as sysdba" :

1. Change the FAILED_LOGIN_ATTEMPTS profile to UNLIMITED.
alter profile default limit failed_login_attempts unlimited password_life_time unlimited;

2. Sql to change the status from LOCKED to OPEN  (copy the result and run in sqlplus).

select 'alter user '|| username || ' account unlock;' 
from dba_users where account_status = 'LOCKED'

3. Sql to remove the expired status (copy the result and run in sqlplus).
select 'alter user ' || su.name || ' identified by values' || ' ''' || spare4 || ';' || su.password || ''';'
from sys.user$ su join dba_users du on ACCOUNT_STATUS like 'EXPIRED%'
and su.name = du.username;


Good Luck ...

Wednesday, May 21, 2014

Find FND_PROFILE's changed by specific USER

Hi All ...

Here the small sql that will help you to find which FND_PROFILE's were changed by specific USER on your EBS instance.

select fpot.user_profile_option_name , decode(fpov.level_id,10001,'SITE'
          ,10002,'APPLICATION'
          ,10003,'RESPONSIBILITY'
          ,10004,'USER') Profile_Level , fpov.profile_option_value , fpov.last_update_date
          from fnd_profile_options fpo
               , fnd_profile_options_tl fpot
               , fnd_profile_option_values fpov
          where fpo.profile_option_name = fpot.profile_option_name
          and  fpo.profile_option_id  = fpov.profile_option_id
          and fpov.last_updated_by = (select user_id from fnd_user

          where user_name  = '&USERNAME')​

Good Luck ...

Wednesday, May 7, 2014

Script to compile APPS schema without running adadmin


Hi All ...

Here the  Script to compile APPS schema without running adadmin.


As the appl user in linux, define both env vars :
export APPS_PASS=xxxx
export  SYSTEM_PASS=xxxx

Then Run:

#R12
sqlplus -s APPS/$APPS_PASS @$AD_TOP/sql/adutlrcmp.sql APPLSYS $APPS_PASS APPS $APPS_PASS $SYSTEM_PASS 0 0 NONE FALSE

#11i
sqlplus -s APPS/$APPS_PASS @$AD_TOP/admin/sql/adutlrcmp.pls APPLSYS $APPS_PASS APPS $APPS_PASS $SYSTEM_PASS 0 0 NONE FALSE


Good Luck ...

Wednesday, April 30, 2014

R12 Restart Apache + Clear Cache Concurrent


Hi All,

Here the step by step guide for creating Concurrent to Restart Apache + Clear Cache in R12 EBS instance.
Hope that it will save your time during upgrade cycles and users tests.

Here we go....

1. Login to EBS with System Administrator responsibility.
2. Go to Concurrent --> Program --> Executable.
Executable : XX_RESTART_APACHE
Short Name : XX_RESTART_APACHE
Application : Your XX Custom Application
Description : Restart Apache
Execution Method : Host
Execution File Name : Restart_Apache

3. Save your changes.
4. Go to Concurrent --> Program --> Define
Program : XX Restart Apache
Short Name : XX_RESTART_APACHE
Application : Your XX Custom Application
Description : Restart Apache
In Executable Section:
Name : XX_RESTART_APACHE
Method : Host
5. Save your changes.
6. Create Restart_Apache.prog under your CUSTOM_TOP/bin directory:

########################################################
#!/bin/ksh

ORIG_CONC_OUTPUT_FILE=$1
COPIES=$2
TITLE=$3

REQUEST_ID=`echo $TITLE | awk -F"." '{ print $NF }'`


LOG_DIR=$APPLCSF/$APPLLOG
OUT_DIR=$APPLCSF/$APPLOUT
LOG_FILE=l${REQUEST_ID}.req
OUT_FILE=o${REQUEST_ID}.out
USER_LOG_FILE=$LOG_DIR/$LOG_FILE # this is the log file that the user see

echo log file is $LOG_DIR
echo out file is $OUT_DIR
echo user log file is $USER_LOG_FILE

$ADMIN_SCRIPTS_HOME/adoacorectl.sh stop 2>&1  $LOG_FILE
sleep 5
$ADMIN_SCRIPTS_HOME/adoacorectl.sh status 2>&1 $LOG_FILE
sleep 5
echo "Before clear cash"
rm -Rf $ORA_CONFIG_HOME/10.1.3/j2ee/oacore/persistence/* >> $LOG_FILE
echo "After clear cash"
$ADMIN_SCRIPTS_HOME/adoacorectl.sh start 2>&1 $LOG_FILE
sleep 5
$ADMIN_SCRIPTS_HOME/adoacorectl.sh status 2>&1 $LOG_FILE
########################################################

7. chmod +x <YOUR CUTOM_TOP>/bin/Restart_apache.prog
8. Create soft link 
ln -s $FND_TOP/bin/fndcpesr <YOUR CUTOM_TOP>/bin/Restart_apache

9. Add you concurrent to request group under the System Administrator.

That's all...
Good Luck ... 



Tuesday, February 28, 2012

Re-create soft links script for Concurrent Program (Host)

Hi All


Here the small script that will help you to re-create links for Concurrent Program (Host).
During the Rapid Clones and Customization Migration from 11i to R12 the custom prog links in $CUSTOM_TOP/bin are broken.


Usage: ./recreate_prog_links.sh $CUST_TOP


#!/bin/ksh
export CUST_PATH=$1
cd $CUST_PATH/bin
echo "PATH: "  $CUST_PATH/bin
echo "Start re-creating links..."
for f in *.prog
do
PROG_FILE=$f
LINK_FILE=`echo $PROG_FILE | awk -F"." '{ print $1 }'`
LINK_FILE=`ls $LINK_FILE`
if [ "$LINK_FILE" = "" ]
then
echo "Prog File not need relink ...."
else
unlink $LINK_FILE
ln -s $PWD/../../../fnd/12.0.0/bin/fndcpesr $LINK_FILE
### The fndcpesr path need to be changed according the EBS version
For 11i the command : ln -s $PWD/../../../fnd/11.5.0/bin/fndcpesr $LINK_FILE

fi;
done;
echo "Re-creating links finished..."


Guy LiorAnother way to do it (provided by programmer Guy Lior)  it's to run the following sql command in pl/sql developer / sqlplus / toad : 



select 'ln -s $FND_TOP/bin/fndcresr $'||fap.basepath||'/bin/'||fev.executable_name
from   fnd_application     fap,
       fnd_executables_vl  fev
where  fap.application_short_name in ('<Your Application Short name>')
and    fap.application_id = fev.application_id
and    fev.execution_method_code = 'H'

And then just run the received results on Linux server.

Good Luck ...



Sunday, February 19, 2012

Easy Patching

Hi All

My friend Pinhas Rozner working as Oracle Application DBA and SOA Admin Consultant write the Easy Patching script.

I'm using it a lot and want to share it with You...

What you need to do:
1. Create defaultsfile as follow :
run adpatch defaultsfile=$APPL_TOP/admin/$SID/defaults.txt
Now abort autopatch section at point where it asks for patch directory by ctrl + c or ctrl + d
Now check if this file exists.

YOU HAVE TO DO ABOVE STEPS ONLY ONCE IN AN ENVIRONMENT TO CREATE DEFAULTS FILE.

2. Run the script patchrun.sh with the follow parameters:
$1 - driver name
$2 - number of workers to use
$3 - more adpatch options, adding manualy more options for the patch installation

YOU MUST BE IN THE PATCH DRIVER FOLDER

3. Script patchrun.sh
LOG=`echo $PWD |awk -F/ '{print $NF}'`
adpatch defaultsfile=$APPL_TOP/admin/$TWO_TASK/defaults.txt driver=$1 workers=$2 patchtop=$PWD logfile=${LOG}.log $3

Good Luck and  Enjoy Patching ...

How to Create and Support APPS Read-Only DB user

Hi All


Here You can find the scripts for creating APPS read-only DB user.


1. Create tablespace for APPS Read-only user (optional):
create tablespace APPS_RO datafile '<dbf top path>/apps_ro01.dbf'

size                                                  10M
autoextend on maxsize                       200M
extent management local uniform size  64K;


2. Create APPS read-only DB user:
create user apps_ro identified by apps_ro default tablespace  APPS_RO  temporary tablespace TEMP;


3.Grant  APPS read-only DB User:
grant connect, resource to  APPS_RO;


4. Linux SH Script add_to_apps_ro.sh:

#!/bin/ksh
SYSTEM_PWD=$1
OBJECT=$2
OBJECT=`echo $OBJECT | tr [:lower:] [:upper:]`
export SYSTEM_PWD OBJECT


if [ "$SYSTEM_PWD" = "" ] || [ "$OBJECT" = "" ]
then
echo "Usage: install_conc.sh <system password> <object_name>"
echo "For all DB objects please run: add_to_apps_ro.sh <system password> < % >" 
exit
fi;


if [ "$OBJECT" = "%" ]
then
echo "The procedure will run for all DB objects"
echo "--------------------------------------------"
echo "All DB objects will be added to APPS_RO user..."
echo "--------------------------------------------"
sqlplus "/as sysdba" << EOF
@apps_ro_all_create.sql
EOF
echo "Done..."
exit
fi;


echo "--------------------------------------------"
echo $OBJECT " will be added to APPS_RO user..."
echo "--------------------------------------------"
sqlplus "/as sysdba" << EOF
@apps_ro_object_create.sql $OBJECT
EOF
echo "Done..."


5. apps_ro_all_create.sql Script

set serveroutput on size 99999
set verify off
set feedback off
set pagesize 0
set linesize 150
set verify off
spool cre_grant.sql
select 'grant select on ' || owner || '.'|| object_name || ' to apps_ro;' 
FROM   all_objects
where    object_type IN ('VIEW', 'TABLE')
/
spool off
set serveroutput on size 99999
set verify off
set feedback off
set pagesize 0
set linesize 150
set verify off
spool cre_synonym.sql
select 'create or replace synonym apps_ro.' || object_name || ' for '  || owner || '.'|| object_name || ';'
FROM   all_objects
where    object_type IN ('VIEW', 'TABLE')
/
spool off
@cre_grant.sql
/
@cre_synonym.sql
/
exit


6. apps_ro_object_create.sql  Script:

set serveroutput on size 99999
set verify off
set feedback off
set pagesize 0
set linesize 150
set verify off
spool cre_grant.sql
select 'grant select on ' || owner || '.'|| object_name || ' to apps_ro;' 
FROM   all_objects
where    object_type IN ('VIEW', 'TABLE')
and object_name = '&1'
/
spool off
set serveroutput on size 99999
set verify off
set feedback off
set pagesize 0
set linesize 150
set verify off
spool cre_synonym.sql
select 'create or replace synonym apps_ro.' || object_name || ' for '  || owner || '.'|| object_name || ';'
FROM   all_objects
where    object_type IN ('VIEW', 'TABLE')
and object_name = '&1'
/
spool off
@cre_grant.sql
/
@cre_synonym.sql
/
exit

7 . How to use it:

  • Connect to Linux server with oracle user.
  • Create Folder apps_ro and put sh and sql's there.
  • chmod +x add_to_apps_ro.sh
  • Run add_to_apps_ro.sh

Usage: install_conc.sh <system password> <object_name>
For all DB objects please run: add_to_apps_ro.sh <system password> < % >" 


8 . Schedule the compilation apps_ro invalid objects (conditional).


Good Luck ...

Sunday, February 5, 2012

Send mail in HTML format from Oracle Alert manager

Hi All


My customer asked me if there is any way to send the mail from Oracle Alert Manager in HTML format.
I checked a lot of documentation and blogs but still not found the way to do it. As I understand, only plain text can be sent.


But Oracle Alert Manager can not only send message, but also run Linux script, sql statement and concurrent request.
Here the workaround to send HTML mail with Linux Script


1. Go to Alert Manager --> Define
Create a new Alert (Ex. SEND_HTML_MAIL). In Select Statement  write the following test sql:
select '"select * from dba_objects where status = ''INVALID''"' into &OUTPUT from dual
In the end of procedure you will receive the mail with  results for statement: 
"select * from dba_objects where status = 'INVALID' "
(Pay attention: The sql statement need to be with " )


 2. Actions
Create New Action as Summary --> Go to Action Details



3.  Choose 
Action Type: Operating System Script
Application: Your Custom Top
File:  send_mail.sh &OUTPUT  <'YOUR MAIL'>
where :
&OUTPUT - you sql statement
YOUR MAIL - mail address (may be more than one )
Place the send_mail.sh file in $YOUR_CUSTOM_TOP/bin directory



4. Go to Action Sets.

5. Go to Action Details.
6. Save your Alert.

7. send_mail.sh:

export SQL=$1 #Sql Statement to send
export EMAIL_LIST=$2 # To Mail List
export CC_EMAIL_LIST=<cc mail> # Cc Mail List
export BCC_EMAIL_LIST=<bcc mail> # Bcc Mail List
export LOG_FILE="/tmp/htmlwithsqlplus.log";
export SUBJECT="HTML With SQLPlus";
export SENDMAIL="/usr/sbin/sendmail";
#If you are in 11i OA version, you can get your apps password from  wdbsvr.app

export APPS_PWD=`cat $IAS_ORACLE_HOME/Apache/modplsql/cfg/wdbsvr.app |grep -i -B1 apps |grep password |awk '{print $3 }'`

#You really don.t need to edit anything past the variables, unless you are familiar with HTML and sqlplus formatting options. Having a little bit of HTML knowledge could be using in making the emails more appealing.
#The following creates the email header:
# create header

echo "To: ${EMAIL_LIST}" > ${LOG_FILE};
echo "Cc: ${CC_EMAIL_LIST}" >> ${LOG_FILE};
echo "Bcc: ${BCC_EMAIL_LIST}" >> ${LOG_FILE};

echo "Subject: ${SUBJECT}" >> ${LOG_FILE};
echo "Content-Type: text/html; charset=\"us-ascii\"" >> ${LOG_FILE};
echo "" >> ${LOG_FILE};
#The following creates the start of the HTML content:
# message Starts
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">" >> ${LOG_FILE};
echo "<html>" >> ${LOG_FILE};
echo "<head>" >> ${LOG_FILE};
echo "<title></title>" >> ${LOG_FILE};
echo "</head>" >> ${LOG_FILE};
echo "<body bgcolor=\"#ffffff\" text=\"#000000\">" >> ${LOG_FILE};
#Now it's time for the output of sqlplus:
# message body
#If you are in 11i OA version the set markup html on not set.
#So you need to use the IAS_ORACLE_HOME sqlplus version.

export ORACLE_HOME=$IAS_ORACLE_HOME
$IAS_ORACLE_HOME/bin/sqlplus -s apps/$APPS_PWD >> ${LOG_FILE} <<EOF
set markup html on
set feedback off
set PAGES 100
$SQL;
EOF
# finish message
echo "</body>" >> ${LOG_FILE};
echo "</html>" >> ${LOG_FILE};
#The following sends the message:
# mail the logfile results
${SENDMAIL} -t < ${LOG_FILE};


Good Luck ...