The UNIX and Linux Forums  

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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
making a archive script jimmyc Shell Programming and Scripting 1 09-15-2007 01:02 AM
Script to archive file indira UNIX for Dummies Questions & Answers 0 05-22-2007 07:15 AM
Archive Script-Urgent indira HP-UX 1 05-16-2007 10:31 AM
Archive script old files kayarsenal Shell Programming and Scripting 1 08-24-2006 10:46 PM
script to archive all the log files tintedwindow Shell Programming and Scripting 0 06-13-2006 07:51 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-15-2007
Registered User
 

Join Date: Feb 2007
Posts: 41
Stumble this Post!
File Archive Script

Hi There,

I want to create a script that will archive files out of a log folder into seperate folders below it, but I need it to keep the previous 2 days worth of information. Now I know I can easily get a script to put the files in there but I don't know how to only get files older than 2 days, my problem is that the file name doesn't have a date in it so i'll need to use the following date to decide which ones to archive
-rw-r--r-- 1 ugpea eupuk 1824 15 Feb 14:14 submit_rep_15141419_4042930.log
-rw-rw-r-- 1 eupuk eupuk 400483 15 Feb 14:14 med_main.log
-rw-r--r-- 1 root system 4001576 15 Feb 14:15 jobwatch_eupuk.log
-rw-r--r-- 1 root system 50384302 15 Feb 14:15 socketserver_eupuk.log
-rw-rw-r-- 1 eupuk eupuk 374478 15 Feb 14:15 provision_script.log

I think I can use an awk command but have never used it before, does anyone know what command I should use?

Thanks in advance.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-15-2007
Registered User
 

Join Date: Dec 2005
Location: Boston, USA
Posts: 65
Stumble this Post!
use this

find $(Directory_PATH} -mtime +2 -type f | grep "$(Directory_PATH}[^/]*$" | grep -v '/rf/'
e.g
find /common/home/xyz/ -mtime +2 -type f | grep "/common/home/xyz/[^/]*$" | grep -v '/rf/'

Above command will give you list of files older than 2 days. Now use cp or mv command to move the above files to archive directory and compress them as required.

--Manish
Reply With Quote
  #3 (permalink)  
Old 02-15-2007
Registered User
 

Join Date: Feb 2007
Posts: 41
Stumble this Post!
Cheers Manish
Reply With Quote
  #4 (permalink)  
Old 02-15-2007
Registered User
 

Join Date: Jul 2006
Posts: 183
Stumble this Post!
question

The first step itself is getting all the files older than 2 days. Why should we use grep here.
Reply With Quote
  #5 (permalink)  
Old 02-16-2007
Registered User
 

Join Date: Dec 2005
Location: Boston, USA
Posts: 65
Stumble this Post!
second step "grep" is used to exclude the subdirectories if there are any. If you have nested directories, first step would give you results from all the directires, which is the not the case we wanted. Thats the reason additional grep is there to grep out files from current directory only.

-Manish
Reply With Quote
  #6 (permalink)  
Old 02-26-2007
Registered User
 

Join Date: Feb 2007
Posts: 41
Stumble this Post!
Manish,

I have entered the following

root@gmt_prd:/cer_eupuk/log> find /cer_eupuk/log -mtime +2 -type f | grep "/cer_eupuk/log[^/]*$ | grep -v '/rf/'
>

And all I get is the prompt to enter data???? I'm confused

Any help please.
Reply With Quote
  #7 (permalink)  
Old 02-26-2007
Registered User
 

Join Date: Aug 2005
Location: Bangalore
Posts: 196
Stumble this Post!
Quote:
Originally Posted by KeesH
Manish,

I have entered the following

root@gmt_prd:/cer_eupuk/log> find /cer_eupuk/log -mtime +2 -type f | grep "/cer_eupuk/log[^/]*$ | grep -v '/rf/'
>

And all I get is the prompt to enter data???? I'm confused

Any help please.
double quotes are missing in the first grep

find /cer_eupuk/log -mtime +2 -type f | grep "/cer_eupuk/log[^/]*$" | grep -v '/rf/'
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
mtime

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:41 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0