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

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.? :confused::confused:

You can use below

 
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 {} \ ;

1 Like