Move log files with date and delete older than 3 weeks


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Move log files with date and delete older than 3 weeks
# 1  
Old 05-09-2013
Move log files with date and delete older than 3 weeks

I have written a script which generate one logfile on every sunday and thursday
I want to move the older log files into /tmp directory befor generating new one so i used mv command like
Code:
mv usr/sbin/appl/logfile.txt  usr/sbin/appl/tmp

2) But when i move this file to /tmp it will replace the older one.. So i want that logfile name should be changed befor moving /tmp
log file name should contain date
for example. logfile_9May13
3) Also i dont want to keep the logfiles into /tmp directory which are more than 3 weeks older.

Can anyone help me to achive theses two things into my script.? SmilieSmilie
# 2  
Old 05-09-2013
You can use below

Code:
 
mv usr/sbin/appl/tmp/logfile.txt  usr/sbin/appl/tmp/logfile_`date +"%d%b%y"`.txt
find usr/sbin/appl/tmp/logfile*.txt  -mtime +21 -exec rm {} \ ;

This User Gave Thanks to vidyadhar85 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to move files older than certain time?

If there are 100 files created in a directory /data/ today from 2:00 AM to 10:00 AM I need to move files older than 3:00 AM to a new directory /hold/ How to do that? Also, if I have to move files between 3:00 AM to 9:00 AM, how to achieve that (3 Replies)
Discussion started by: eskay
3 Replies

2. UNIX for Dummies Questions & Answers

How to delete all the files older than a date?

Hi, I need a command for deleting all the compress files *.Z that are older than the current date - 5 days. Basically I have a directory where daily I meet some back up files and I want to remove automatically the ones 5 days (or more) older than the current date. How can I write a 'rm' command... (1 Reply)
Discussion started by: Francy
1 Replies

3. Shell Programming and Scripting

Delete log files content older than 30 days and append the lastest date log file date

To delete log files content older than 30 days and append the lastest date log file date in the respective logs I want to write a shell script that deletes all log files content older than 30 days and append the lastest log file date in the respective logs This is my script cd... (2 Replies)
Discussion started by: sreekumarhari
2 Replies

4. UNIX for Advanced & Expert Users

HPUX move files older than 30 days

Hello, I have a script which finds files in a directory that are older than 30 days and moves them to the specified directory. The problem is I don't know why it works the way it does? Code: find . -name '*.sql' ! -mtime -30 -exec mv '{}' /dataload/archivelogs \; I was under the... (4 Replies)
Discussion started by: pure_jax
4 Replies

5. UNIX for Dummies Questions & Answers

move files older than 2 days to another folder

Hi I am facing problem in using this command, mv `find /export/june/PURGEDATA*.txt -mtime +2 -exec ls {} \;` june/archive/ mv: Insufficient arguments (1) Usage: mv f1 f2 mv f1 ... fn d1 mv d1 d2 Thank you in advance (2 Replies)
Discussion started by: vishwakar
2 Replies

6. Shell Programming and Scripting

Move file older date

hlow all i have folder with name like this 20110512 20110601 20110602 so i want move the last 1 day to other directory for example this date 20110602 so i want move folder older 1 day from this date 20110512 -----> this folder will move to other dir 20110601-----> this folder will move... (2 Replies)
Discussion started by: zvtral
2 Replies

7. Emergency UNIX and Linux Support

How to delete all the files which are more than 3 weeks old in a particular directory.Thnx in advanc

(12 Replies)
Discussion started by: rajsharma
12 Replies

8. Shell Programming and Scripting

Delete the files older than 3 weeks in a particular directory.

Hi, Friends, I am writing a script to delete all the files which are there for more than 3 weeks. I have tried this : find /home/appl/backup -type f -mtime +21 -exec rm -f {} \; But i am not sure if it deletes only the files in specified directory or all the directorinies in the provieded... (3 Replies)
Discussion started by: rajsharma
3 Replies

9. Shell Programming and Scripting

Delete files older than 3 months.(read date from the name of the file)

Guys, My log files stored in the date format format below(log_20080714072942): TIMESTAMP=`date +%Y%m%d%H%M%S` LOG=/log/log_${TIMESTAMP}.log I'm looking for a shell script which deletes all files which is older than 3 months from today. Regards, Bhagat (3 Replies)
Discussion started by: bhagat.singh-j
3 Replies

10. Shell Programming and Scripting

how to check whether the given file is 5 weeks older than current date

HI, I need to check whether the given file is 5 weeks older than current date ?? Can anyone give me the script for this ?? (1 Reply)
Discussion started by: risshanth
1 Replies
Login or Register to Ask a Question