Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Computing > NZ Computing > shell script for running as a weekly cron job

Reply
Thread Tools

shell script for running as a weekly cron job

 
 
NOSPAM@NOSPAM.invalid.com
Guest
Posts: n/a
 
      12-11-2004
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."

 
Reply With Quote
 
 
 
 
Alex Axolotl
Guest
Posts: n/a
 
      12-11-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) 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

 
Reply With Quote
 
 
 
 
Bok
Guest
Posts: n/a
 
      12-11-2004
(E-Mail Removed) 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?
 
Reply With Quote
 
rupert
Guest
Posts: n/a
 
      12-11-2004
You shouldn't need to restart the log process - you may be able to get away
with echo > my.log

<(E-Mail Removed)> wrote in message
newsan.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."
>



 
Reply With Quote
 
Enkidu
Guest
Posts: n/a
 
      12-11-2004
On Sat, 11 Dec 2004 14:17:43 +1300, "(E-Mail Removed)"
<(E-Mail Removed)> 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
 
Reply With Quote
 
NOSPAM@NOSPAM.invalid.com
Guest
Posts: n/a
 
      12-11-2004
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."

 
Reply With Quote
 
Enkidu
Guest
Posts: n/a
 
      12-11-2004
On Sat, 11 Dec 2004 20:16:00 +1300, "(E-Mail Removed)"
<(E-Mail Removed)> 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
 
Reply With Quote
 
NOSPAM@NOSPAM.invalid.com
Guest
Posts: n/a
 
      12-11-2004
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.

 
Reply With Quote
 
Enkidu
Guest
Posts: n/a
 
      12-11-2004
On Sat, 11 Dec 2004 22:41:20 +1300, "(E-Mail Removed)"
<(E-Mail Removed)> 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
 
Reply With Quote
 
Lawrence D’Oliveiro
Guest
Posts: n/a
 
      12-13-2004
In article <pan.2004.12.11.07.15.58.95598@TRACKER>,
"(E-Mail Removed)" <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Equiv of a CRON job? Andrew Banks ASP .Net 8 07-30-2012 07:03 AM
Re: cron job or EJB timer? Arne Vajhj Java 1 09-13-2008 04:26 PM
execute a shell script in a shell script moongeegee Perl Misc 2 12-04-2007 12:18 AM
cron job times out Nikola Skoric Python 0 11-24-2006 06:50 PM
running perl script in cron Edward Perl Misc 1 05-13-2004 05:11 PM



Advertisments