![]() |
|
|
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 |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread |
Rating:
|
Display Modes |
|
|
|
||||
|
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. |
|
||||
|
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 |
|
||||
|
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 |
|
||||
|
Quote:
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 |
![]() |
| Bookmarks |
| Tags |
| mtime |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|