#!/bin/bash export ORACLE_SID=$1 export ORACLE_HOME=/u01/app/oracle/product/12.2.0/dbhome_1 export PATH=$PATH:$ORACLE_HOME/bin # Define the location of the log files log_dir="/u01/app/oracle/logs" # Define the name of the log file prefix log_prefix="rman_delete_logs" # Get the current date and time today=$(date +%F_%H-%M-%S) # Construct the full path and name of the log file log_file="$log_dir/$log_prefix-$today.log" # Connect to the database using RMAN and redirect output to the log file rman target / >> $log_file 2>&1 << EOF # Delete all archive logs crosscheck archivelog all; delete noprompt archivelog all; delete noprompt expired archivelog all; # End the RMAN session exit; EOF # Rotate the log files find $log_dir -type f -name "$log_prefix*" -mtime +7 -exec rm {} \; # Output a message indicating that the archive logs have been deleted and logged echo "All archive logs have been deleted using RMAN. Output has been logged to $log_file and older logs have been rotated."