Need Help Urgently - ksh Script

Requirement is to list the files older than 365 days from multiple directories and delete them and log the list of files which are deleted to a log file.

so 1 script should only list files older than 365 days for each directory separately to a folder

The other script should read these files and delete them and log the list of items which are deleted.

I am attaching the script i have for reference and the listing script and the output of the first script.

It is only listing for first directory not rest of the directories and i don't know how to keep write delete script.

Please help.

Can you post the commands and where you stuck? We might be able to help more quickly then.

BTW, we have another forum for urgent issues.

this is the script i am using

#####################This script finds, logs and deletes files and folders older than 365 days.#################
#/bin/ksh

DIRS_TO_FIND="/home/,
                /db/,
                /db/backup/,
                /staging/,
                /staging/codedrops/,
                /db/*/db2dump/"

$DIR_LOG_FILE="/staging/retain_for_2years/unix_clean_up_Test/logs/list_to_be_deleted.log"

TIMESTAMP=`date +%Y:%m:%d`

DAYS_OLD="365" # This will find and delete folders and files older than 365 days.

IFS=$','

echo "....................................." >> $DIR_LOG_FILE

echo "Starting Generation job on : $TIMESTAMP" >> $DIR_LOG_FILE

for DIR in $DIRS_TO_FIND;

do

echo "Looking for Files in $DIR" >> $DIR_LOG_FILE

find $DIR -type f -mtime +$DAYS_OLD >> $DIR_LOG_FILE

echo "Generated list of Deleted files" >> $DIR_LOG_FILE

done
unset IFS
echo "Generation of files $NOW completed" >> $DIR_LOG_FILE

But it is only getting files older than 365 for /home directory but not next and i want to the log file to be generated for each directory.. so pleas ehelp.

You don't need comma. Also, you don't even need the loop.

DIRS_TO_FIND="/home/ /db/ /db/backup/ /staging/ /staging/codedrops/ /db/*/db2dump/"
find "$DIRS_TO_FIND" -type f -mtime +$DAYS_OLD >> $DIR_LOG_FILE

Note the space between paths

1 Like

Everyone at the UNIX and Linux Forums gives their best effort to reply to all questions in a timely manner. For this reason, posting questions with subjects like "Urgent!" or "Emergency" and demanding a fast reply are not permitted in the regular forums.

For members who want a higher visibility to their questions, we suggest you post in the Emergency UNIX and Linux Support Forum. This forum is given a higher priority than our regular forums.

Posting a new question in the Emergency UNIX and Linux Support Forum requires forum Bits. We monitor this forum to help people with emergencies, but we do not not guarantee response time or best answers. However, we will treat your post with a higher priority and give our best efforts to help you.

If you have posted a question in the regular forum with a subject "Urgent" "Emergency" or similar idea, we will, more-than-likely, close your thread and post this reply, redirecting you to the proper forum.

Of course, you can always post a descriptive subject text, remove words like "Urgent" etc. (from your subject and post) and post in the regular forums at any time.

Thank you.

The UNIX and Linux Forums