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.

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

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 ^^

#!/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

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.

-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.