I wrote a shell script program that supposed to delete any directories and its files that begin with the same character string . The program is designed to delete directories and its files that are one day old or less and only the directories that begin with the same character string. The problem is the program doesn't delete the directories. I don't know why the script isn't working. The OS is Linux redhats. Version 6 x.
Here is the shell script
#!/bin/bash -x
NUMBER_OF_DAYS=1
MOUNT_PATH=/saswork
echo "Script Started"
echo "Deleting the files greater than ${NUMBER_OF_DAYS}"
cd ${MOUNT_PATH}
chmod 755 SAS_work*
find ${MOUNT_PATH} -mtime +${NUMBER_OF_DAYS} -name "SAS_work*"
find ${MOUNT_PATH} -mtime +${NUMBER_OF_DAYS} -name "SAS_work*" | while read DIR_NAME
do
echo "Removing the ${DIR_NAME}"
rm -rf "${DIR_NAME}"
done
echo "Script Completed"
Below are sample of the directories that the program should delete if the directories are one day old or less.
drwx------ 4 exxc_prxd exxc_prxd 8192 Mar 15 14:49 SAS_work08480000328E_svxxsa60001mz34
drwx------ 4 izjlin D02012192 8192 Jul 14 08:57 SAS_work8BFF000059ED_svxxsi60001mz33
drwx------ 4 jxwm67 D02012192 8192 Jul 16 19:32 SAS_work8CA50000264B_svxxsi60001mz33
drwx------ 4 ixjiinz D02012192 8192 Jul 15 11:17 SAS_work9417000072ED_svcxsi60001mz34
drwx------ 3 tale4 D02017434 8192 Mar 13 14:30 SAS_workAA0C000044B7_svcxksi60001m34
drwx------ 4 ixjwinz D02012192 8192 Apr 12 09:23 SAS_workBA37000044E9_svxxxcksi60001mz34
drwx------ 4 bdmknyex D02017434 8192 Mar 15 09:41 SAS_workE77600003715_svcksi60001mz34