purging of Files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting purging of Files
# 1  
Old 10-20-2009
purging of Files

Hello All,

I want to delete the files based on the days. like, Files available under directory /abc want to delete if they are older than 15 days.
Files available under directory /pqr want to delete if they are 7 days old and some files under directory /xyz should get deleted if they are older than 3 days. The Script will be executed through Cronjob at particular Time on daily basis.
While deleting the files it should not check for Sat and Sunday.

Like, if the script executed today, while deleting the files under directory /xyz (older than 3 days) should not delete the files with date of Monday, Friday and Thursday.
The date format on the files will be yyyymmdd.

Thank you very much in advance.
# 2  
Old 10-20-2009
And where is your issue?

You are not expecting us to write the code for you without having at least tried something, are you?
# 3  
Old 10-20-2009
I didn't asked to write the code for me. I just asked how to avoid the Saturday and Sunday while calculating the days.
I have written day's functions like.

function back_3days
{
typeset today=$(date +%Y%m%d)

LASTDAY=$(prev_day $today)
LASTDAY=$(prev_day $LASTDAY)
LASTDAY=$(prev_day $LASTDAY)
print $LASTDAY
}

where prev_day will calculate the total date's in a month and provide the date of the prev_day.
# 4  
Old 10-20-2009
What about weekends then, will cron job run?
In which case it will erase on sunday the file it should not on monday...
# 5  
Old 10-20-2009
The files will be generated only from Monday to Friday. No file will generate on weekends. Cronjob will run only on these 5 days.
# 6  
Old 10-20-2009
So your cron on friday should count on 3 days, and the other week days on 5 (thursday shall not touch monday files and wednesday, you have the weekend...)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Automate splitting of files , scp files as each split completes and combine files on target server

i use the split command to split a one terabyte backup file into 10 chunks of 100 GB each. The files are split one after the other. While the files is being split, I will like to scp the files one after the other as soon as the previous one completes, from server A to Server B. Then on server B ,... (2 Replies)
Discussion started by: malaika
2 Replies

2. UNIX for Dummies Questions & Answers

Purging logic

Hi guys i am having following files in a directory a_07:15:13.txt a_07:16:13.txt a_07:17:13.txt a_07:18:13.txt a_07:19:13.txt a_date file will be created on a day to day basics so that it may pileup on a long go.So i need to create a logic so that the files will be gunzipped to a backup... (1 Reply)
Discussion started by: mohanalakshmi
1 Replies

3. Shell Programming and Scripting

Purging 2000+ directories efficiently

Hi I have a requirement wherein i need to purge some directories. I have more than 2000 directories where i need to keep data for 10 days and delete the rest. What i am looking for is an efficient way to achieve this. There are four mount points from where i need to delete the files. ... (3 Replies)
Discussion started by: Apoorvbarwa
3 Replies

4. Shell Programming and Scripting

Disc space issues and purging of files

Hi All, I am looking forward to create a unix shell script to purge the files. The requirement is: 1) Do df -k and check the current space occupied for the /a1 folder. 2) If the space consumed is greater than 90 %, delete all the DEF* files from a subfolder /a1/archive. Example: df... (4 Replies)
Discussion started by: shilpa_acc
4 Replies

5. Shell Programming and Scripting

Fine Tune - Huge files/directory - Purging

Hi Expert's, I need your assitance in tunning one script. I have a mount point where almost 4848008 files and 864739 directories are present. The script search for specific pattern files and specfic period then delete them to free up space. The script is designed to run daily and its taking around... (19 Replies)
Discussion started by: senthil.ak
19 Replies

6. Shell Programming and Scripting

Shell script for purging the 3 days old files

Hi all, I try to write shell script to the below requirement. I have Hard coded the oratab location and take the list of databases from oratab and find out archive log locations for each database, and list more than 3 days old files for each location and purge those. ... (2 Replies)
Discussion started by: mak_boop
2 Replies

7. Shell Programming and Scripting

How to retrieve all the linked script files/ctl files/sql files?

Hi I am going to migrate our datawarehouse system from HP Tru 64 Unix to the Red Hat Linux. Inside the box, it is running around 40 cron jobs; inside each cron job, it is calling other shell script files, and the shell script files may again call other shell script files or ctl files(for... (1 Reply)
Discussion started by: franksubramania
1 Replies

8. Shell Programming and Scripting

Error While Purging Files

find /filearchive/ -type f -mtime +7 -exec rm weblogs*.log {} \; This worked only if this comand is executed int he unix comand prompt, but when i put this in the shell script it is not recognizing the file.It says weblogs: No such file or directory Am i doing anything wrong here ? (4 Replies)
Discussion started by: svishh123
4 Replies

9. Shell Programming and Scripting

Purging a Set of Files

Hi Frineds, I want to delete a set of files which are older than 7 days from teh current date.I am totally enw to shell scripting, can anyone help me with a sample code to list out the files which are older and then remove them from the directory. Please help THanks Viswa (5 Replies)
Discussion started by: svishh123
5 Replies

10. Shell Programming and Scripting

Purging script

Hi, Need to change the following command to also purge the child directories after /data/tmp within one command (recursively check for X number of days old files and purge accordingly)? e.g. /data/tmp/a, /data/tmp/a/b, /data/tmp/log. find /data/tmp -type f -mtime +7 -exec rm -f {} \; ... (2 Replies)
Discussion started by: egls
2 Replies
Login or Register to Ask a Question