I have created a script which should delete the directories and it's contents older then 2 days. The script is working fine but the directory is not getting deleted. Kindly help, it will be much appreciated.
export BACKUP_SETS=/backupset/ if [ ! -d "$BACKUP_SETS" ]; then # Control will enter here if $DIRECTORY doesn't exist. printf "\nFailure when removing BACKUP_SETS, Exiting \n" exit 1 else two_days=$(date -d "2 days ago" +%Y_%b_%d) for f in $BACKUP_SETS[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]; do [ -d "$f" ] || continue (( $f < $two_days )) && echo rm -r "$f" done printf "\n BACKUP_SETS was removed successfully.\n" fi
The directory contains folder as mentioned below.
[oracle@ backupset]$ ls -lrt total 12 drwxr-xr-x 2 oracle dba 12288 Jul 23 18:32 2018_Aug_23
Output of the script:
[oracle@ backupset]$ ./backupset.sh BACKUP_SETS was removed successfully.