How to tar, compress and remove files older than two days


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to tar, compress and remove files older than two days
# 1  
Old 04-20-2009
How to tar, compress and remove files older than two days

Hi,

I'm Eddy from Belgium and I've the following problem.

I try to write a ksh script in AIX to tar, compress and remove the original *.wav files from the directory belgacom_sf_messages older than two days with the following commands.

The problem is that I do not find a good combination to handle this.


#!/bin/ksh
#
MAIN_DIR=/tmp/belgacom_sf_messages
integer set COMPRESSDAYS=3
integer set DELETEDAYS=3
tar -cvf - ${MAIN_DIR} 2>/tmp/file.tar
#
find ${MAIN_DIR} ! -name \*.wav -mtime -3 -exec gzip {} \;
find ${MAIN_DIR} -name \*.gz -mtime -3 -exec rm {} \;
#
##########Tested and ok##########
#tar -cvf - ${MAIN_DIR} 2> /tmp/Eddy.tar |gzip -c1 > file.tar.Z


Can somebody advises me how to do this.

Thanks in advance.

Best regards.
Eddy.

Last edited by edr; 04-22-2009 at 05:00 AM..
# 2  
Old 04-20-2009
Hi Eddy,

this is not AIX specific - I move this thread to Shell Programming and Scripting - The UNIX and Linux Forums. Also use CODE tags to display code, logs, data etc., ty.

Maybe try something like this
Code:
find ${MAIN_DIR} ! -name \*.wav -mtime -3 -exec tar uvf eddy.tar {} \;
gzip eddy.tar

If you are going to archive this often, maybe add a date into the filename or something. Also when specifiying variables like those with ...DAYS=3, use them in your commands ^^
# 3  
Old 04-20-2009
Code:
#!/bin/ksh
#
MAIN_DIR=/tmp/belgacom_sf_messages
find ${MAIN_DIR} -name *.wav -mtime -3 > FILE_LIST
tar -cvf archive1.tar -L FILE_LIST
gzip archive1.tar
for x in ${FILE_LIST}
rm  $x
done
rm FILE_LIST


didn't test it. Bit looks like it should work
# 4  
Old 04-22-2009
Question

Hi.

Thanks a lot for helping me.
There is one thing I do not understand.
I 've four wav files with a different date.

-rw-r----- 1 dtuser staff 258904 Apr 22 09:53 3210223758_73072441618_20090415151440972.wav
-rw-r----- 1 dtuser staff 192504 Apr 21 09:53 3210224056_73073919768_20090418102231949.wav
-rw-r----- 1 dtuser staff 258904 Apr 20 09:53 3210223758_73072441618_20090415151440972.wav
-rw-r----- 1 dtuser staff 192504 Apr 19 09:53 3210224056_73073919768_20090418102231949.wav

Using the recommended commands in my test scrip have no making any sense.

find ${MAIN_DIR} -name *.wav -mtime -3 > FILE_LIST
or
find ${MAIN_DIR} -name \*.wav -mtime -3 -exec mv {} \;

-mtime -3 or -mtime -5 or -mtime -10 makes no difference.
The result is that all files are compressed and removed instaed of the files of three days old.

Best regards.
Eddy.
# 5  
Old 04-22-2009
-mtime -3 means the find criteria is for looking files modified in the last 3 days

In your case, you need to use -mtime +3 as you want to perform it on files older than 3 days.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compress folders older than x days

hello everyone. in /opt/abc every night there is a new folder created. in that folder there is aseries of files created for that day. i would like to run a script every Sunday night at 02:00 to compress each file separately (preserving its name) who is older than 2 days. i have found this... (2 Replies)
Discussion started by: atux
2 Replies

2. Shell Programming and Scripting

How to create zip/gz/tar files for if the files are older than particular days in UNIX or Linux?

I need a script file for backup (zip or tar or gz) of old log files in our unix server (causing the space problem). Could you please help me to create the zip or gz files for each log files in current directory and sub-directories also? I found one command which is to create gz file for the... (4 Replies)
Discussion started by: Mallikgm
4 Replies

3. UNIX for Dummies Questions & Answers

How to compress the directories which is older than 7 days?

Hi all, how to compress the directories which is older 7 days. If any one knows please help me this is urgent. Thanks in advance (3 Replies)
Discussion started by: rameshpagadala
3 Replies

4. Shell Programming and Scripting

Remove files older than 2 days.

Hi All, I am new to the scripting and using solaris 10 OS. Please suggest me from the below script which modifications need to be done to delete the files more that 2days older. Current script is deleting existing file. # Remove old explorer runs if needed DIR=`dirname ${EXP_TARGET}` if ... (2 Replies)
Discussion started by: Navkreddy
2 Replies

5. Shell Programming and Scripting

script to remove files older than 60 days

Hi I need help in the script which looks at a contorl file which has a list of file names like xxxx.12345 and I want to take only xxxxx and search in a specific directory and remove the file if its older than 60 days I have written something like this.. but seems to be wrong... (1 Reply)
Discussion started by: antointoronto
1 Replies

6. Shell Programming and Scripting

Need script to tar files older than 30 days

Hi all. Here's my situation: I have performance reports that run every 30 minutes saved in the format: stats_report_11251000.txt stats_report_11251030.txt stats_report_11251100.txt stats_report_11251130.txt (Obviously run at Nov 25 10 AM, 10:30 AM, 11 AM and so on...) I would... (2 Replies)
Discussion started by: jamie_collins
2 Replies

7. Solaris

Find files older than x days and create a consolidated single tar file.

Hello, I need help in finding files older than x days and creating a single consolidated tar file combining them. Can anyone please provide me a script? Thanks, Dawn (3 Replies)
Discussion started by: Dawn Bosch
3 Replies

8. Shell Programming and Scripting

Need to remove files older than 30 days except directories

Hi, I need to remove files (*.trc) which are older than 30 days from one location. My problem is there I do not want to visit any of the directories at that location. I want to search files at that particular location only (need to skip directorys at that location). maxdepth option is there... (6 Replies)
Discussion started by: malaymaru
6 Replies

9. UNIX for Dummies Questions & Answers

Find files older than 5 days and remove tem after listing

need help with this ... Find files older than 5 days and remove tem after listing list "test" file older than 5 days and then remove them (1 Reply)
Discussion started by: ypatel6871
1 Replies

10. UNIX for Dummies Questions & Answers

tar files older than 30 days

Hi there, I am trying to tar a number of files held in a specific folder. I am only interested in archiving files older than 30 days. Having read through the man entries and all available documentation I thought I'd cracked the coomand with tar -c -z -v -N 15/04/2004 -f /wfch.tar * This... (6 Replies)
Discussion started by: wfch
6 Replies
Login or Register to Ask a Question