![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Removing files older than 7 days | texasoeb | UNIX for Dummies Questions & Answers | 3 | 04-20-2007 04:04 PM |
| Need to remove files older than 30 days except directories | malaymaru | Shell Programming and Scripting | 6 | 11-13-2006 11:50 PM |
| Find files older than 5 days and remove tem after listing | ypatel6871 | UNIX for Dummies Questions & Answers | 1 | 09-05-2005 11:00 AM |
| tar files older than 30 days | wfch | UNIX for Dummies Questions & Answers | 6 | 04-19-2004 04:40 AM |
| delete files older than 7 days | lesstjm | UNIX for Dummies Questions & Answers | 1 | 11-06-2001 10:43 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 04:00 AM.. |
|
|||||
|
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
|
|
||||
|
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 |
|
||||
|
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. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|