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 and shell scripting languages 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 05:02 AM
Script to archive file indira UNIX for Dummies Questions & Answers 0 05-22-2007 11:15 AM
Archive Script-Urgent indira HP-UX 1 05-16-2007 02:31 PM
Archive script old files kayarsenal Shell Programming and Scripting 1 08-25-2006 02:46 AM
script to archive all the log files tintedwindow Shell Programming and Scripting 0 06-13-2006 11:51 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 4.00 average. Display Modes
  #1 (permalink)  
Old 02-15-2007
KeesH KeesH is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 41
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.
  #2 (permalink)  
Old 02-15-2007
Manish Jha Manish Jha is offline
Registered User
  
 

Join Date: Dec 2005
Location: Boston, USA
Posts: 65
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
  #3 (permalink)  
Old 02-15-2007
KeesH KeesH is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 41
Cheers Manish
  #4 (permalink)  
Old 02-15-2007
dsravan dsravan is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 188
question

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

Join Date: Dec 2005
Location: Boston, USA
Posts: 65
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
  #6 (permalink)  
Old 02-26-2007
KeesH KeesH is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 41
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.
  #7 (permalink)  
Old 06-09-2008
dwm4p dwm4p is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 3
Quote:
Originally Posted by Manish Jha View Post
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
Hi Manish, et. al.

I'm getting to the game late here, but am interested in performing a similar function, modified slightly to remove the files that are more than 2 days old - less of an archive, more of a clean up/forced log control.

What do you suggest to be the cleanest method for adding a 'rm' action to this command?

TIA,
Dan
Closed Thread

Bookmarks

Tags
mtime

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 06:26 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