Mailing List Archive

how to set cron to run freshclam
Hello,
I am not that much experienced with linux.
I would like to have freshclam doing updates by itself. Until now I did
the update manually.
The clamav-update file in my /etc/cron.d directory is as follow:

## Adjust this line...
MAILTO=root,postmaster,webmaster,clamav

## It is ok to execute it as root; freshclam drops privileges and
becomes
## user 'clamav' as soon as possible
0 */3 * * * root /usr/share/clamav/freshclam-sleep

how should I edit it to have it work ?

The shell script freshclam-sleep it is supposed to run "points" to a
freshclam file in the /etc/sysconfig directoryand in this file I
commmented (#) the FRESHCLAM_DELAY=disabled-warn line

From what I understand, the freshclam-sleep script should be run
every 3 hours. The cron.hourly directory is empty.
Also I gathered that I should add a line in the/my crontab to run
freshclam as a cron task.
Before I mess everything up, can someone tell me how to set the cron
thing to run freshclam this way.
Thanx in advance.
Pascal

_______________________________________________
Help us build a comprehensive ClamAV guide: visit http://wiki.clamav.net
http://lurker.clamav.net/list/clamav-users.html
Re: how to set cron to run freshclam [ In reply to ]
On Fri, 2007-04-13 at 13:26 +0200, Pascal Duchatelle wrote:
> Hello,
> I am not that much experienced with linux.
> I would like to have freshclam doing updates by itself. Until now I did
> the update manually.
> The clamav-update file in my /etc/cron.d directory is as follow:
>
> ## Adjust this line...
> MAILTO=root,postmaster,webmaster,clamav
>
> ## It is ok to execute it as root; freshclam drops privileges and
> becomes
> ## user 'clamav' as soon as possible
go

vi /etc/cron.hourly/freshclam

then add

/usr/local/bin/freshclam --quiet -l /var/log/clamav/freshclam.log

Then save and then:

chmod 0755 /etc/cron.hourly/freshclam

It will run updates every hour, if you want to update once a day then
use cron.daily if once a week use cron.weekly.
> 0 */3 * * * root /usr/share/clamav/freshclam-sleep
>
> how should I edit it to have it work ?
>
> The shell script freshclam-sleep it is supposed to run "points" to a
> freshclam file in the /etc/sysconfig directoryand in this file I
> commmented (#) the FRESHCLAM_DELAY=disabled-warn line
>
> From what I understand, the freshclam-sleep script should be run
> every 3 hours. The cron.hourly directory is empty.
> Also I gathered that I should add a line in the/my crontab to run
> freshclam as a cron task.
> Before I mess everything up, can someone tell me how to set the cron
> thing to run freshclam this way.
> Thanx in advance.
> Pascal
>
> _______________________________________________
> Help us build a comprehensive ClamAV guide: visit http://wiki.clamav.net
> http://lurker.clamav.net/list/clamav-users.html

_______________________________________________
Help us build a comprehensive ClamAV guide: visit http://wiki.clamav.net
http://lurker.clamav.net/list/clamav-users.html
Re: how to set cron to run freshclam [ In reply to ]
Le Fri, 13 Apr 2007 15:42:43 +0200,
Roger M <roger@wack.co.za> a écrit :

> On Fri, 2007-04-13 at 13:26 +0200, Pascal Duchatelle wrote:
> > Hello,
> > I am not that much experienced with linux.
> > I would like to have freshclam doing updates by itself. Until now I
> > did the update manually.
> > The clamav-update file in my /etc/cron.d directory is as follow:
> >
> > ## Adjust this line...
> > MAILTO=root,postmaster,webmaster,clamav
> >
> > ## It is ok to execute it as root; freshclam drops privileges and
> > becomes
> > ## user 'clamav' as soon as possible
> go
>
> vi /etc/cron.hourly/freshclam
Thank you Roger,
but since cron.whateverly are directories (I have Fedora core 6)
and the files in them are script shell files, I guess that the first
line in the freshclam file that I open/create shoud be :
#!/bin/sh
Am I right ?
Thank you again
Pascal
>
> then add
>
> /usr/local/bin/freshclam --quiet -l /var/log/clamav/freshclam.log
>
> Then save and then:
>
> chmod 0755 /etc/cron.hourly/freshclam
>
> It will run updates every hour, if you want to update once a day then
> use cron.daily if once a week use cron.weekly.
> > 0 */3 * * * root /usr/share/clamav/freshclam-sleep
> >
> > how should I edit it to have it work ?
> >
> > The shell script freshclam-sleep it is supposed to run "points" to a
> > freshclam file in the /etc/sysconfig directoryand in this file I
> > commmented (#) the FRESHCLAM_DELAY=disabled-warn line
> >
> > From what I understand, the freshclam-sleep script should be run
> > every 3 hours. The cron.hourly directory is empty.
> > Also I gathered that I should add a line in the/my crontab to run
> > freshclam as a cron task.
> > Before I mess everything up, can someone tell me how to set the cron
> > thing to run freshclam this way.
> > Thanx in advance.
> > Pascal
> >
> > _______________________________________________
> > Help us build a comprehensive ClamAV guide: visit
> > http://wiki.clamav.net
> > http://lurker.clamav.net/list/clamav-users.html
>
> _______________________________________________
> Help us build a comprehensive ClamAV guide: visit
> http://wiki.clamav.net http://lurker.clamav.net/list/clamav-users.html
_______________________________________________
Help us build a comprehensive ClamAV guide: visit http://wiki.clamav.net
http://lurker.clamav.net/list/clamav-users.html
Re: how to set cron to run freshclam [ In reply to ]
Roger M wrote:
> On Fri, 2007-04-13 at 13:26 +0200, Pascal Duchatelle wrote:
>> Hello,
>> I am not that much experienced with linux.
>> I would like to have freshclam doing updates by itself. Until now I did
>> the update manually.
>> The clamav-update file in my /etc/cron.d directory is as follow:
>>
>> ## Adjust this line...
>> MAILTO=root,postmaster,webmaster,clamav
>>
>> ## It is ok to execute it as root; freshclam drops privileges and
>> becomes
>> ## user 'clamav' as soon as possible
> go
>
> vi /etc/cron.hourly/freshclam
>
> then add
>
> /usr/local/bin/freshclam --quiet -l /var/log/clamav/freshclam.log
>
> Then save and then:
>
> chmod 0755 /etc/cron.hourly/freshclam
>
> It will run updates every hour, if you want to update once a day then
> use cron.daily if once a week use cron.weekly.

This is pretty much a bad idea. There is a tendency to run cron jobs thus:

0 * * * * freshclam

Imagine thousands of people doing this and the load it imposes on the
servers at the top of each hour. Better is to put in a time randomizer
so that your freshclam is not fired off in lockstep with thousands of
others. This simple bash code segment has been suggested (kudos to author):


if [ -z "$1" ]; then
/usr/bin/bash -c 'sleep $[ RANDOM % 1800 ]'
fi

This creates a random number between 1 and 900 that becomes the number
of seconds the code sleeps before jumping into the fray. In this case
the delay can be up to 30 minutes (1800 seconds).

To prevent concurrent sessions from running you should keep the delay
time value less than the cron period + run time of freshclam.

The $1 allows you the option to over-ride the delay as in:

freshclam.sh now

So you might ask 'what is the benefit', and it is this: running a mirror
is a huge bandwidth hog, and helping the sysadmins balance their loads
with simple code like this shows we care about their concerns and that
we respect appreciate their contribution and show it in our usage
patterns. And it may prevent their being discouraged to the point of
shutting down their mirror.

dp
_______________________________________________
Help us build a comprehensive ClamAV guide: visit http://wiki.clamav.net
http://lurker.clamav.net/list/clamav-users.html
Re: how to set cron to run freshclam [ In reply to ]
Dennis Peterson wrote:

>
>
> if [ -z "$1" ]; then
> /usr/bin/bash -c 'sleep $[ RANDOM % 1800 ]'
> fi
>
> This creates a random number between 1 and 900 that becomes the number
> of seconds the code sleeps before jumping into the fray.

Damn - that should have been '1 and 1800'. First coffee of the morning
syndrome kind of oops.

dp
_______________________________________________
Help us build a comprehensive ClamAV guide: visit http://wiki.clamav.net
http://lurker.clamav.net/list/clamav-users.html
Re: how to set cron to run freshclam [ In reply to ]
Le Fri, 13 Apr 2007 08:26:42 -0700,
Dennis Peterson <dennispe@inetnw.com> a écrit :

> Roger M wrote:
> > On Fri, 2007-04-13 at 13:26 +0200, Pascal Duchatelle wrote:
> >> Hello,
> >> I am not that much experienced with linux.
> >> I would like to have freshclam doing updates by itself. Until now
> >> I did the update manually.
> >> The clamav-update file in my /etc/cron.d directory is as follow:
> >>
> >> ## Adjust this line...
> >> MAILTO=root,postmaster,webmaster,clamav
> >>
> >> ## It is ok to execute it as root; freshclam drops privileges and
> >> becomes
> >> ## user 'clamav' as soon as possible
> > go
> >
> > vi /etc/cron.hourly/freshclam
> >
> > then add
> >
> > /usr/local/bin/freshclam --quiet -l /var/log/clamav/freshclam.log
> >
> > Then save and then:
> >
> > chmod 0755 /etc/cron.hourly/freshclam
> >
> > It will run updates every hour, if you want to update once a day
> > then use cron.daily if once a week use cron.weekly.
>
> This is pretty much a bad idea. There is a tendency to run cron jobs
> thus:
>
> 0 * * * * freshclam
>
> Imagine thousands of people doing this and the load it imposes on the
> servers at the top of each hour. Better is to put in a time
> randomizer so that your freshclam is not fired off in lockstep with
> thousands of others. This simple bash code segment has been suggested
> (kudos to author):
>
>
> if [ -z "$1" ]; then
> /usr/bin/bash -c 'sleep $[ RANDOM % 1800 ]'
> fi
>
Dennis.
since I am not much familiar with bash scripting, where is the
reference to the frashclam run command in the above if statement ?
is it the -z ? from what I understand the /usr/bin/bash -c 'sleep
$[ RANDOM % 1800 ]' passes a string as an option to the bash to make it
sleep for 1 to 1800 sec randomly.
Thank you
Pascal


> This creates a random number between 1 and 900 that becomes the
> number of seconds the code sleeps before jumping into the fray. In
> this case the delay can be up to 30 minutes (1800 seconds).
>
> To prevent concurrent sessions from running you should keep the delay
> time value less than the cron period + run time of freshclam.
>
> The $1 allows you the option to over-ride the delay as in:
>
> freshclam.sh now
>
> So you might ask 'what is the benefit', and it is this: running a
> mirror is a huge bandwidth hog, and helping the sysadmins balance
> their loads with simple code like this shows we care about their
> concerns and that we respect appreciate their contribution and show
> it in our usage patterns. And it may prevent their being discouraged
> to the point of shutting down their mirror.
>
> dp
> _______________________________________________
> Help us build a comprehensive ClamAV guide: visit
> http://wiki.clamav.net http://lurker.clamav.net/list/clamav-users.html
_______________________________________________
Help us build a comprehensive ClamAV guide: visit http://wiki.clamav.net
http://lurker.clamav.net/list/clamav-users.html
Re: how to set cron to run freshclam [ In reply to ]
On Sunday 15 April 2007 2:45 am, Pascal Duchatelle wrote:
> Le Fri, 13 Apr 2007 08:26:42 -0700,
>
> Dennis Peterson <dennispe@inetnw.com> a écrit :
> > Roger M wrote:
> > > On Fri, 2007-04-13 at 13:26 +0200, Pascal Duchatelle wrote:
> > >> Hello,
> > >> I am not that much experienced with linux.
> > >> I would like to have freshclam doing updates by itself. Until now
> > >> I did the update manually.
> > >> The clamav-update file in my /etc/cron.d directory is as follow:
> > >>
> > >> ## Adjust this line...
> > >> MAILTO=root,postmaster,webmaster,clamav
> > >>
> > >> ## It is ok to execute it as root; freshclam drops privileges and
> > >> becomes
> > >> ## user 'clamav' as soon as possible
> > >
> > > go
> > >
> > > vi /etc/cron.hourly/freshclam
> > >
> > > then add
> > >
> > > /usr/local/bin/freshclam --quiet -l /var/log/clamav/freshclam.log

> > This is pretty much a bad idea. There is a tendency to run cron jobs
> > thus:
> >
> > 0 * * * * freshclam
> >
> > Imagine thousands of people doing this and the load it imposes on the
> > servers at the top of each hour. Better is to put in a time
> > randomizer so that your freshclam is not fired off in lockstep with
> > thousands of others. This simple bash code segment has been suggested
> > (kudos to author):
> >
> >
> > if [ -z "$1" ]; then
> > /usr/bin/bash -c 'sleep $[ RANDOM % 1800 ]'
> > fi
>
> Dennis.
> since I am not much familiar with bash scripting, where is the
> reference to the frashclam run command in the above if statement ?
> is it the -z ? from what I understand the /usr/bin/bash -c 'sleep
> $[ RANDOM % 1800 ]' passes a string as an option to the bash to make it
> sleep for 1 to 1800 sec randomly.
> Thank you
> Pascal
>

I have this tiny script located in /usr/local/bin/freshclamcron:

#!/bin/bash

sleep $[ RANDOM % 3000 ]
/usr/bin/freshclam --quiet --daemon-notify=/etc/clamd.conf
exit

I run it at 2 minutes after each hour, it will sleep for a random amount of
time, up to 50 minutes, run freshclam and notify clamd of updates. The entry
in my /etc/crontab file looks like this:

2 * * * * clamav /usr/local/bin/freshclamcron

HTH

--
Chris
KeyID 0xE372A7DA98E6705C
Re: how to set cron to run freshclam [ In reply to ]
Pascal Duchatelle wrote:
> Le Fri, 13 Apr 2007 08:26:42 -0700,
> Dennis Peterson <dennispe@inetnw.com> a écrit :
>
>> Roger M wrote:
>>> On Fri, 2007-04-13 at 13:26 +0200, Pascal Duchatelle wrote:
>>>> Hello,
>>>> I am not that much experienced with linux.
>>>> I would like to have freshclam doing updates by itself. Until now
>>>> I did the update manually.
>>>> The clamav-update file in my /etc/cron.d directory is as follow:
>>>>
>>>> ## Adjust this line...
>>>> MAILTO=root,postmaster,webmaster,clamav
>>>>
>>>> ## It is ok to execute it as root; freshclam drops privileges and
>>>> becomes
>>>> ## user 'clamav' as soon as possible
>>> go
>>>
>>> vi /etc/cron.hourly/freshclam
>>>
>>> then add
>>>
>>> /usr/local/bin/freshclam --quiet -l /var/log/clamav/freshclam.log
>>>
>>> Then save and then:
>>>
>>> chmod 0755 /etc/cron.hourly/freshclam
>>>
>>> It will run updates every hour, if you want to update once a day
>>> then use cron.daily if once a week use cron.weekly.
>> This is pretty much a bad idea. There is a tendency to run cron jobs
>> thus:
>>
>> 0 * * * * freshclam
>>
>> Imagine thousands of people doing this and the load it imposes on the
>> servers at the top of each hour. Better is to put in a time
>> randomizer so that your freshclam is not fired off in lockstep with
>> thousands of others. This simple bash code segment has been suggested
>> (kudos to author):
>>
>>
>> if [ -z "$1" ]; then
>> /usr/bin/bash -c 'sleep $[ RANDOM % 1800 ]'
>> fi
>>
> Dennis.
> since I am not much familiar with bash scripting, where is the
> reference to the frashclam run command in the above if statement ?
> is it the -z ? from what I understand the /usr/bin/bash -c 'sleep
> $[ RANDOM % 1800 ]' passes a string as an option to the bash to make it
> sleep for 1 to 1800 sec randomly.
> Thank you
> Pascal
>

The next line might be something like this:

/usr/local/bin/freshclam --quiet -l /var/log/clamav/freshclam.log

That will run fresh clam without any output to the console, and it will
log the transaction as indicated.

The other assumption is that you will not start freshclam in daemon mode.

dp
_______________________________________________
Help us build a comprehensive ClamAV guide: visit http://wiki.clamav.net
http://lurker.clamav.net/list/clamav-users.html