shell script for running as a weekly cron job

Discussion in 'NZ Computing' started by NOSPAM@NOSPAM.invalid.com, Dec 11, 2004.

  1. Guest

    Hi, folks.

    Does anyone have a shell script which can be used as a cron job to
    periodically check the size of a particular log file, to gzip it if it
    gets too large then replace it with a new empty file and then restart
    the logging daemon so that it uses the new log file?

    I've never written a shell script and I'm now wanting to learn about
    that aspect of using the command line.

    Any help or suggestions would be appreciated.


    Divine

    --
    "Even the most fanatical Microsoft supporter has to see that Longhorn has
    become Shorthorn."
     
    , Dec 11, 2004
    #1
    1. Advertising

  2. Alex Axolotl Guest

    wrote:
    > Hi, folks.
    >
    > Does anyone have a shell script which can be used as a cron job to
    > periodically check the size of a particular log file, to gzip it if it
    > gets too large then replace it with a new empty file and then restart
    > the logging daemon so that it uses the new log file?
    >
    > I've never written a shell script and I'm now wanting to learn about
    > that aspect of using the command line.
    >
    > Any help or suggestions would be appreciated.
    >
    >
    > Divine
    >


    Heres a good place to start
    http://www.icon.co.za/~psheer/book/node10.html.gz
     
    Alex Axolotl, Dec 11, 2004
    #2
    1. Advertising

  3. Bok Guest

    wrote:
    > Does anyone have a shell script which can be used as a cron job to
    > periodically check the size of a particular log file, to gzip it if it
    > gets too large then replace it with a new empty file and then restart
    > the logging daemon so that it uses the new log file?
    >
    > Any help or suggestions would be appreciated.


    Have you considered logrotate?
     
    Bok, Dec 11, 2004
    #3
  4. rupert Guest

    You shouldn't need to restart the log process - you may be able to get away
    with echo > my.log

    <> wrote in message
    news:pan.2004.12.11.01.17.42.672151@TRACKER...
    > Hi, folks.
    >
    > Does anyone have a shell script which can be used as a cron job to
    > periodically check the size of a particular log file, to gzip it if it
    > gets too large then replace it with a new empty file and then restart
    > the logging daemon so that it uses the new log file?
    >
    > I've never written a shell script and I'm now wanting to learn about
    > that aspect of using the command line.
    >
    > Any help or suggestions would be appreciated.
    >
    >
    > Divine
    >
    > --
    > "Even the most fanatical Microsoft supporter has to see that Longhorn has
    > become Shorthorn."
    >
     
    rupert, Dec 11, 2004
    #4
  5. Enkidu Guest

    On Sat, 11 Dec 2004 14:17:43 +1300, ""
    <> wrote:

    >Hi, folks.
    >
    >Does anyone have a shell script which can be used as a cron job to
    >periodically check the size of a particular log file, to gzip it if it
    >gets too large then replace it with a new empty file and then restart
    >the logging daemon so that it uses the new log file?
    >
    >I've never written a shell script and I'm now wanting to learn about
    >that aspect of using the command line.
    >
    >Any help or suggestions would be appreciated.
    >

    Why re-invent the wheel? See logrotate.

    What's your distro?

    Cheers,

    Cliff
    --

    The National Party manifesto can be viewed here:

    http://www.labour.org.nz/policy/index.html
     
    Enkidu, Dec 11, 2004
    #5
  6. Guest

    On Sat, 11 Dec 2004 18:32:39 +1300, Enkidu wrote:

    >>Does anyone have a shell script which can be used as a cron job to
    >>periodically check the size of a particular log file, to gzip it if it
    >>gets too large then replace it with a new empty file and then restart
    >>the logging daemon so that it uses the new log file?
    >>
    >>I've never written a shell script and I'm now wanting to learn about
    >>that aspect of using the command line.
    >>
    >>Any help or suggestions would be appreciated.
    >>

    > Why re-invent the wheel? See logrotate.
    >
    > What's your distro?


    Smoothwall - a custom router/firewall box. I think it's based on a RedHat
    distro, but is highly modified and very much cut down to the absolute
    basics.

    It "rotates" the logs at the end of every month, but one log -
    "messages" gets extremely large before the end of the month, and some
    months that particular partition runs out of space. And something on that
    box is constantly monitoring what is being written into that file, because
    even when I delete it and create another file of the same name, the
    web interface (from which most configurations can be changed) does not
    show a change of usage of that partition untill I reboot that box -
    which is a total pain.

    That is why I now keep a closer eye on the size of that particular log.
    But I would rather have a script do it automatically via CRON.


    Divine

    --
    "Even the most fanatical Microsoft supporter has to see that Longhorn has
    become Shorthorn."
     
    , Dec 11, 2004
    #6
  7. Enkidu Guest

    On Sat, 11 Dec 2004 20:16:00 +1300, ""
    <> wrote:

    >On Sat, 11 Dec 2004 18:32:39 +1300, Enkidu wrote:
    >
    >>>Does anyone have a shell script which can be used as a cron job to
    >>>periodically check the size of a particular log file, to gzip it if it
    >>>gets too large then replace it with a new empty file and then restart
    >>>the logging daemon so that it uses the new log file?
    >>>
    >>>I've never written a shell script and I'm now wanting to learn about
    >>>that aspect of using the command line.
    >>>
    >>>Any help or suggestions would be appreciated.
    >>>

    >> Why re-invent the wheel? See logrotate.
    >>
    >> What's your distro?

    >
    >Smoothwall - a custom router/firewall box. I think it's based on a RedHat
    >distro, but is highly modified and very much cut down to the absolute
    >basics.
    >
    >It "rotates" the logs at the end of every month, but one log -
    >"messages" gets extremely large before the end of the month, and some
    >months that particular partition runs out of space. And something on that
    >box is constantly monitoring what is being written into that file, because
    >even when I delete it and create another file of the same name, the
    >web interface (from which most configurations can be changed) does not
    >show a change of usage of that partition untill I reboot that box -
    >which is a total pain.
    >
    >That is why I now keep a closer eye on the size of that particular log.
    >But I would rather have a script do it automatically via CRON.
    >

    Check logrotate.conf or equivalent on that distro. There MUST be
    something that rotates the logs. Check:
    crontab -l (as root)
    /etc/crontab
    /etc/cron.d
    /etc/cron.daily
    /etc/cron.weekly
    /etc/cron.monthly

    You shouldn't need to write a script.

    Cheers,

    Cliff
    --

    The National Party manifesto can be viewed here:

    http://www.labour.org.nz/policy/index.html
     
    Enkidu, Dec 11, 2004
    #7
  8. Guest

    On Sat, 11 Dec 2004 21:04:33 +1300, Enkidu wrote:

    > Check logrotate.conf or equivalent on that distro. There MUST be
    > something that rotates the logs. Check:
    > crontab -l (as root)
    > /etc/crontab
    > /etc/cron.d
    > /etc/cron.daily
    > /etc/cron.weekly
    > /etc/cron.monthly
    >
    > You shouldn't need to write a script.


    I found logrotate.conf and used VI to change the frequency to weekly
    instead of monthly. I also changed the number of rotated logs to 2 instead
    of 4. That should be more than necessary for my purposes.

    I then forced a rotation of the logs (actually I did that several times)
    now the used space on that partition has dropped back to about 1%.

    I'll give it a month to see if that change will keep everything as it
    should be.

    Thanks, Cliff, for the info on logrotate and crontab - much appreciated.


    Divine

    --
    43 - for those who require slightly more than the answer to life, the universe
    and everything.
     
    , Dec 11, 2004
    #8
  9. Enkidu Guest

    On Sat, 11 Dec 2004 22:41:20 +1300, ""
    <> wrote:

    >On Sat, 11 Dec 2004 21:04:33 +1300, Enkidu wrote:
    >
    >> Check logrotate.conf or equivalent on that distro. There MUST be
    >> something that rotates the logs. Check:
    >> crontab -l (as root)
    >> /etc/crontab
    >> /etc/cron.d
    >> /etc/cron.daily
    >> /etc/cron.weekly
    >> /etc/cron.monthly
    >>
    >> You shouldn't need to write a script.

    >
    >I found logrotate.conf and used VI to change the frequency to weekly
    >instead of monthly. I also changed the number of rotated logs to 2 instead
    >of 4. That should be more than necessary for my purposes.
    >
    >I then forced a rotation of the logs (actually I did that several times)
    >now the used space on that partition has dropped back to about 1%.
    >
    >I'll give it a month to see if that change will keep everything as it
    >should be.
    >
    >Thanks, Cliff, for the info on logrotate and crontab - much appreciated.
    >

    No worries. That's the great thing about Linux. Somebody has usually
    done what you need already. But you can still find something that no
    one else has done. In your case there's already a solution. The real
    buzz comes if you have a solution that others want.

    Cheers,

    Cliff
    --

    The National Party manifesto can be viewed here:

    http://www.labour.org.nz/policy/index.html
     
    Enkidu, Dec 11, 2004
    #9
  10. In article <pan.2004.12.11.07.15.58.95598@TRACKER>,
    "" <> wrote:

    >It "rotates" the logs at the end of every month, but one log -
    >"messages" gets extremely large before the end of the month, and some
    >months that particular partition runs out of space.


    That's why I end up moving large logs into an overflow area on the /home
    partition which is appropriately symlinked from the original location.
     
    Lawrence D’Oliveiro, Dec 13, 2004
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?PHNjcmlwdD5hbGVydCgpOzwvc2NyaXB0Pg==?= a

    <script>alert();</script>

    =?Utf-8?B?PHNjcmlwdD5hbGVydCgpOzwvc2NyaXB0Pg==?= a, Apr 13, 2004, in forum: Microsoft Certification
    Replies:
    0
    Views:
    7,840
    =?Utf-8?B?PHNjcmlwdD5hbGVydCgpOzwvc2NyaXB0Pg==?= a
    Apr 13, 2004
  2. nadiralishah
    Replies:
    0
    Views:
    1,173
    nadiralishah
    Jan 6, 2008
  3. Lalo
    Replies:
    2
    Views:
    1,916
  4. Giuen
    Replies:
    0
    Views:
    1,051
    Giuen
    Sep 12, 2008
  5. partyin
    Replies:
    0
    Views:
    1,107
    partyin
    Feb 21, 2012
Loading...

Share This Page