The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-20-2009
edr edr is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 2
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..
  #2 (permalink)  
Old 04-20-2009
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,259
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 (permalink)  
Old 04-20-2009
Dardeer Dardeer is offline
Registered User
  
 

Join Date: May 2008
Posts: 7
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 (permalink)  
Old 04-22-2009
edr edr is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 2
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 (permalink)  
Old 04-22-2009
dennis.jacob dennis.jacob is offline Forum Advisor  
dj -------
  
 

Join Date: Feb 2007
Location: Singapore/Bangalore/Cochin
Posts: 560
-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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:14 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0