Need Help Urgently - ksh Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need Help Urgently - ksh Script
# 1  
Old 02-27-2015
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.
# 2  
Old 02-27-2015
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.
# 3  
Old 02-27-2015
this is the script i am using

Code:
#####################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.

Last edited by Scrutinizer; 02-27-2015 at 03:10 AM.. Reason: code tags
# 4  
Old 02-27-2015
You don't need comma. Also, you don't even need the loop.

Code:
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
This User Gave Thanks to clx For This Post:
# 5  
Old 02-27-2015
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Please correct my script - Needed very urgently

hello all, I have a script, used to search for the strings from the set of 5 similar pattern file from the log dir. So here it goes . The input parameter is a part of the file name. When during the script execution, the script should parse the input parameter to original file's with the same... (1 Reply)
Discussion started by: raghunsi
1 Replies

2. Shell Programming and Scripting

KSH script to run other ksh scripts and output it to a file and/or email

Hi I am new to this Scripting process and would like to know How can i write a ksh script that will call other ksh scripts and write the output to a file and/or email. For example ------- Script ABC ------- a.ksh b.ksh c.ksh I need to call all three scripts execute them and... (2 Replies)
Discussion started by: pacifican
2 Replies

3. Shell Programming and Scripting

Script command - need help urgently

I have added script command to the .profile of the id, whose session needs to be captured. When exit command is issued, the script command exits. Is there a way to exit the parent shell also - and log off the system completely with one exit command? (8 Replies)
Discussion started by: ggayathri
8 Replies

4. Shell Programming and Scripting

Help need urgently....

I am new to shell scripting I am getting file sample.txt from mainframes to my unix machine Mon-Fri every 15 minutes from 9:00AM to 6:00PM. I need to Compare timestamp of sample.txt against system time via a Unix script kicked off by an Autosys job My Task is to write a shell script to monitor... (3 Replies)
Discussion started by: chinniforu2003
3 Replies

5. Solaris

most urgently about pc-routing

Hi I have knowledge is a little about Solaris 10. I have problem route Question I have two lan interfaces nge0 >> 192.168.1.1 / 24 and link up Client1 >> 192.168.1.10 not out internet (GW 192.168.1.254) nge1 >> 192.168.50.220 /24 and link up Client50 >> 192.168.50.1 can... (2 Replies)
Discussion started by: sermsuk
2 Replies

6. Shell Programming and Scripting

import var and function from ksh script to another ksh script

Ih all, i have multiples ksh scripts for crontab's unix jobs they all have same variables declarations and some similar functions i would have a only single script file to declare my variables, like: var1= "aaa" var2= "bbb" var3= "ccc" ... function ab { ...} function bc { ... }... (2 Replies)
Discussion started by: wolfhurt
2 Replies

7. Shell Programming and Scripting

Need help urgently

Hi to All, I m a regular visitor of this site but this one is my first thread . Although I ve tried but I cant find the solution .:confused: I ve number of files having extension .file., which having some define statement in it.The files consits as follows Ex:- abc.file `define ADCONV0 ... (3 Replies)
Discussion started by: user_prady
3 Replies

8. Shell Programming and Scripting

hi help in writing awk script(urgently)

hi to all i have file like this file.txt this is naryana expect hyderabad is a cool place now climate VISAKHSAPATNAM became very cool #vizag is my birth place #hyderabad is a cool place #now climate of hyd became very cool #vizag is my birth place #hyderabad is a cool place ... (7 Replies)
Discussion started by: LAKSHMI NARAYAN
7 Replies

9. UNIX for Dummies Questions & Answers

Need Information Urgently.

Hi i dont know about the UNIX OS at all but now as my Project requires, i need to learn it as soon as possible. Could anybody please help me out in suggessting any good elementary book on UNIX OS so that atleast i can learn the commands for UNIX servers and at the same time within the short span... (3 Replies)
Discussion started by: sumit_krishan
3 Replies

10. Shell Programming and Scripting

Shell Script needed urgently

Hi Frends, I am need of a small shell script. Kindly any body help me by giving me a small shell script to read first line in a file and extract date from the first line and store it in a variable... and after storing it in a variable the first and the last line of the file has to be deleted..... (2 Replies)
Discussion started by: vas_dba
2 Replies
Login or Register to Ask a Question