File Archive Script | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

File Archive Script

Shell Programming and Scripting


Tags
mtime

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-15-2007
KeesH KeesH is offline
Registered User
 
Join Date: Feb 2007
Last Activity: 20 May 2008, 4:18 AM EDT
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
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.
Sponsored Links
    #2  
Old 02-15-2007
Manish Jha Manish Jha is offline
Registered User
 
Join Date: Dec 2005
Last Activity: 16 June 2009, 1:18 PM EDT
Location: Boston, USA
Posts: 65
Thanks: 0
Thanked 0 Times in 0 Posts
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
Sponsored Links
    #3  
Old 02-15-2007
KeesH KeesH is offline
Registered User
 
Join Date: Feb 2007
Last Activity: 20 May 2008, 4:18 AM EDT
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Cheers Manish
    #4  
Old 02-15-2007
dsravan dsravan is offline
Registered User
 
Join Date: Jul 2006
Last Activity: 10 August 2012, 6:18 AM EDT
Posts: 245
Thanks: 1
Thanked 0 Times in 0 Posts
question

The first step itself is getting all the files older than 2 days. Why should we use grep here.
Sponsored Links
    #5  
Old 02-16-2007
Manish Jha Manish Jha is offline
Registered User
 
Join Date: Dec 2005
Last Activity: 16 June 2009, 1:18 PM EDT
Location: Boston, USA
Posts: 65
Thanks: 0
Thanked 0 Times in 0 Posts
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
Sponsored Links
    #6  
Old 02-26-2007
KeesH KeesH is offline
Registered User
 
Join Date: Feb 2007
Last Activity: 20 May 2008, 4:18 AM EDT
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
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.
Sponsored Links
    #7  
Old 02-26-2007
ahmedwaseem2000 ahmedwaseem2000 is offline
Registered User
 
Join Date: Aug 2005
Last Activity: 14 September 2014, 10:08 PM EDT
Location: Bangalore
Posts: 288
Thanks: 8
Thanked 1 Time in 1 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/'
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Perl script to Archive the data file after the load msrahman Shell Programming and Scripting 2 04-08-2011 12:17 AM
Shell Script for moving 3 days old file to Archive Folder phani333 Shell Programming and Scripting 4 09-14-2010 02:29 AM
script help .. archive dr46014 Shell Programming and Scripting 1 04-28-2009 10:59 AM
Generic Shell Script to Archive a file mak1600 Shell Programming and Scripting 8 07-26-2008 08:51 AM
Script to archive file indira UNIX for Dummies Questions & Answers 0 05-22-2007 10:15 AM



All times are GMT -4. The time now is 03:01 AM.