Find the answer to your Linux question:
Results 1 to 10 of 10
HI All, At present in my server the log folder was filled up and causing memory issue. So I am planning to write a script in such a way that ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2011
    Posts
    6

    need to zip all the files excluding todays file


    HI All,

    At present in my server the log folder was filled up and causing memory issue.
    So I am planning to write a script in such a way that the files which are older than 30 days will be deleted and also need to find the files which were not compressed and need to compress this file. Compression will exclude if the file was created on the same day.

    I am new to Unix .Please bear me.

  2. #2
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,399
    Already done.
    Have a look at logrotate
    Code:
    man logrotate
    You must always face the curtain with a bow.

  3. #3
    Just Joined!
    Join Date
    Jun 2011
    Posts
    6
    Thanks for you help.

    I gone through the man pages.I tried to with some script.
    Can you please have a look
    Code:
    "/var/log/jboss/*.log" {
    missingok
    copytruncate
    rotate 30 -thinking that will keep 30days files
    compress
    notifempty
    sharedscripts
    postrotate
    endscript
    }
    Regards,
    Sreenivas A.

  4. #4
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,399
    The "rotate 30" is ok.
    I think you can omit "sharedscript, postrotate, endscript"
    As there is nothing defined to be executed after rotating.
    In consequence, also sharedscript does nothing.

    The copytruncate will work, at the cost of loosing a few loglines (seconds at most) due to the copy process.
    I cant find in a hurry, if jboss can be signaled to reopen its logfiles.
    In that case, the following might help to have all loglines
    Code:
    compres
    delaycompress
    
    
    sharedscripts
    postrotate
    <SEND SIGNAL TO JBOSS>
    endscript
    Another thing:
    If you installed jboss via package manager (apt-get, yum, etc) then the chance is high, that there is already a logrotate conf for it in /etc/logrotate.d
    Last edited by Irithori; 06-21-2011 at 12:37 PM.
    You must always face the curtain with a bow.

  5. #5
    Just Joined!
    Join Date
    Jun 2011
    Posts
    6
    Thanks for your reply.
    So which means my file will look like
    Code:
    "/var/log/jboss/*.log" {
    missingok
    rotate 30
    compress
    delaycompress
    notifempty
    sharedscripts
    postrotate
    <SEND SIGNAL TO JBOSS>
    endscript
    }
    I think they haven't installed it from package manageer. I haven't seen any file related to jboss in logrotate.d .
    How can I send siganl to JBOSS in postrotate section?

    Regards,
    Sreenivas A.

  6. #6
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,399
    After some digging (I dont use jboss atm) at the usual places and reading specfiles/forums/deb/rpm packages,
    it seems that jboss doesnt play so nice with logrotate.
    This post explains it:
    Why do JBoss and Logrotate create log files full of NUL characters? - Server Fault

    So sorry:
    It seems, the easy way via logrotate cannot be reliably implemented, and instead Log4j needs to be used.
    You must always face the curtain with a bow.

  7. #7
    Just Joined!
    Join Date
    Jun 2011
    Posts
    6
    Thanks Irithori.

    I checked the link and found that it will rename the server.log to server.log.todaydate.

    But it won't compress nor delete the older files. May be I need to logrotate to perform these two task

    is it right?

    Regards,
    Sreenivas A.

  8. #8
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,399
    Unfortunately, I have little experience with log4j, as our projects rarely involve java.
    So I am the wrong guy from here on, sorry.

    I do know, that log4j is the standard and stable java logging framework.
    Most probably it can at least rotate logs.
    Maybe start reading here
    Apache log4j 1.2 - Short introduction to log4j
    and then that
    DailyRollingFileAppender (Apache Log4j 1.2.16 API)
    You must always face the curtain with a bow.

  9. #9
    Just Joined!
    Join Date
    Jun 2011
    Posts
    6
    HI,
    with DailyRollingFileAppender we can rotate the files but we can't zip or delete the files. SO I wrote DailyRollingFileAppender to rotate the files and then for zip and delete we used the below code and placed under /etc/logrotate.d/ folder.
    Code:
    /var/log/jboss/*.log {
    missingok
    copytruncate
    rotate 30
    compress
    notifempty
    }
    then I tried logrotate -f /etc/logrotate.d/jboss
    but still the files were not zipped nor deleted.

    Regards,
    Sreenivas A.

  10. #10
    Just Joined!
    Join Date
    Jun 2011
    Posts
    6
    any inputs please?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •