0

I want to create a shell script for logrotating. following are my requirement.

  1. want to archive the log files to a particular directory lets(/usr/local/jboss-5.10..GA/server/archive/log) older than 2 months .

  2. want to delete logs older than 2 months from archive directory. the format of log is server.log.2015-08-11

    server.log.2015-02-06
    server.log.2015-02-07
    server.log.2015-02-08
    server.log.2015-02-09
    server.log.2015-02-10
    server.log.2015-02-11
    server.log.2015-02-12
    server.log.2015-02-13
    server.log.2015-02-14
    server.log.2015-02-15
    

the log files are present on below path

cd /usr/local/jboss-5.1.0.GA/server/pymidol/log/
  • 1
    Is using logrotate an option? man logrotate for details – KM. Aug 20 '15 at 11:24
  • Sir , i have checked it but not able to make a script .if u can show me the format according to my need then it will be very helpul to me .. – Nishant sahu Aug 20 '15 at 11:47
  • Does jboss create the dated log files? If so, you don't need logrotation as jboss already does that; you simply need archiving. Please clarify in your Question. – roaima Aug 20 '15 at 13:10
  • yes sir but for space management we have to delete logs manually ..so i was seacrhing for a script which can do all my requirement accordingly – Nishant sahu Aug 20 '15 at 13:29
3

first create some space by removing files

for your (2) question for removing the files from arhive directory

find /usr/local/jboss-5.10..GA/server/archive/log -type f  -name server.log.* -mtime +60 -exec rm {} \;

for your (1) question

find /usr/local/jboss-5.10..GA/server/pymidol/log -type f  -name server.log.* -mtime +60 -exec mv {} /usr/local/jboss-5.10..GA/server/archive/log  \;
  • thanks sir for your answer but i want to zip the logs when they move to archive directory\ – Nishant sahu Aug 20 '15 at 13:01
  • so instead of -exec mv ... use -exec gzip – Shravan Yadav Aug 20 '15 at 13:02
  • sir if i use exec gzip and will they move to archive directory as u told to remove -exec mv command – Nishant sahu Aug 20 '15 at 13:08
  • yes replace -exec mv with -exec gzip – Shravan Yadav Aug 20 '15 at 13:10
  • Thanks sir , for your valuable time ... if i will have any query regarding it i will surely post it regarding this topic. – Nishant sahu Aug 20 '15 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.