Deleting files older than X days

A couple of different ways to purge files older than a certain amount of days.

find -type f -mtime +350 -name 'CopyCluster*' -execdir rm -- '{}' \;

If you want to be very precise with the number of days ago you want to delete from then you can find the number of days from now using:

days=$(( ( $(date '+%s') - $(date -d '1 months ago' '+%s') ) / 86400 ))
echo $days

and then use the variable to delete

find /logs/CopyCluster* -mtime +$days -type f -delete

To do this all in one command

find /tmp/*.log -type f \
-mtime "+$(( ( $(date '+%s') - $(date -d '1 months ago' '+%s') ) / 86400 ))" -delete



ADRCI error – DIA-48448: This command does not support multiple ADR homes

Problem: When running adrci on an oracle server with multiple homes, you can get the following error when trying to complete some actions:

DIA-48448: This command does not support multiple ADR homes

Reason is existence of multiple oracle database instances/ASM/Listener homes etc. Solution is to set the ADRCI home for the instance you want to operate.

As the error above stipulates, this is because the adrci home is not set. To check the homes available on the server:

ADRCI: Release – Production on Tue Feb 21 22:03:57 2017

ADR base = “/u01/app/oracle”
adrci> show homes
ADR Homes:

to set the home to listener3, run the following command:

adrci> SET HOME diag/tnslsnr/myhost/listener_scan3

You should now be able to complete actions against this home, such as purging alert logs over X number of days.

OEM Grid Control 10.2 – Purge logs

Came across an issue whereby the OC4J (Oracle Application Server Containers for Java EE) had exponentially grown over time and the em-application.log file was over 40gb. The other big file was the default-web-access.log file which was over 10gb.

As far as i am aware, these files don’t automatically purge and so a manual workaround is required.

To clean up and remove these files do the following. only remove if they are no longer required – if not copy the files first (as in the example below)

Steps taken:

1. Stop Grid Control
2. Move big files into backup file
3. Start Grid Control
4. Once happy, Remove backup files

[**LIVE**]:/u01/app/oracle/product/10.2/gc/oms10g/opmn/bin : df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sdb1             135G   74G   7G  96% /u01
[**LIVE**]:/u01/app/oracle/product/10.2/gc/oms10g/opmn/bin : ./opmnctl stopall
opmnctl: stopping opmn and all managed processes…
[**LIVE**]:/u01/app/oracle/product/10.2/gc/oms10g/opmn/bin : ./opmnctl status
Unable to connect to opmn.
Opmn may not be up.
[**LIVE**]:/u01/app/oracle/product/10.2/gc/oms10g/opmn/bin : cd /u01/app/oracle/product/10.2/gc/oms10g/j2ee/OC4J_EM/log/OC4J_EM_default_island_1
[**LIVE**]:/u01/app/oracle/product/10.2/gc/oms10g/j2ee/OC4J_EM/log/OC4J_EM_default_island_1 : ls -ltrh
total 49G
drwxrwx—    2 oracle   dba          4.0K Nov  8  2005 oc4j
-rw-r–r–    1 oracle   dba          8.9G Jun 22 10:59 default-web-access.log
-rw-rw—-    1 oracle   dba          828M Jun 22 10:59 server.log
-rw-rw—-    1 oracle   dba           40K Jun 22 10:59 rmi.log
-rw-rw—-    1 oracle   dba           20K Jun 22 10:59 jms.log
-rw-rw—-    1 oracle   dba           93K Jun 22 10:59 global-application.log
-rw-r–r–    1 oracle   dba           39G Jun 22 10:59 em-application.log
[**LIVE**]:/u01/app/oracle/product/10.2/gc/oms10g/j2ee/OC4J_EM/log/OC4J_EM_default_island_1 : mv em-application.log em-application.log.backup
[**LIVE**]:/u01/app/oracle/product/10.2/gc/oms10g/j2ee/OC4J_EM/log/OC4J_EM_default_island_1 : mv default-web-access.log default-web-access.log.backup
[**LIVE**]:/u01/app/oracle/product/10.2/gc/oms10g/j2ee/OC4J_EM/log/OC4J_EM_default_island_1 : cd /u01/app/oracle/product/10.2/gc/oms10g/opmn/bin/
[**LIVE**]:/u01/app/oracle/product/10.2/gc/oms10g/opmn/bin : ./opmnctl startall
opmnctl: starting opmn and all managed processes…
[**LIVE**]:/u01/app/oracle/product/10.2/gc/oms10g/opmn/bin : ./opmnctl status

Processes in Instance:
ias-component      | process-type       |     pid | status
HTTP_Server        | HTTP_Server        |   24406 | Alive
LogLoader          | logloaderd         |     N/A | Down
dcm-daemon         | dcm-daemon         |   25611 | Alive
OC4J               | home               |   24407 | Alive
OC4J               | OC4J_EMPROV        |   24408 | Alive
OC4J               | OC4J_EM            |   24409 | Alive
OC4J               | OCMRepeater        |   24417 | Alive
WebCache           | WebCache           |   24439 | Alive
WebCache           | WebCacheAdmin      |   24427 | Alive
DSA                | DSA                |     N/A | Down

[**LIVE**]:/u01/app/oracle/product/10.2/gc/oms10g/opmn/bin : cd –
[**LIVE**]:/u01/app/oracle/product/10.2/gc/oms10g/j2ee/OC4J_EM/log/OC4J_EM_default_island_1 : rm em-application.log.backup
[**LIVE**]:/u01/app/oracle/product/10.2/gc/oms10g/j2ee/OC4J_EM/log/OC4J_EM_default_island_1 : rm default-web-access.log.backup
[**LIVE**]:/u01/app/oracle/product/10.2/gc/oms10g/j2ee/OC4J_EM/log/OC4J_EM_default_island_1 : df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sdb1             135G   74G   55G  58% /u01