Easyish Cron help please

I have never done a cron before so just want to check how to do it properly. I need to do this daily
What I want to do is run /usr/bin/freshclam then if posible write something to a file with a time stamp that says this has been done.

Is it as simple as going to /etc/cron.daily creating a new file and saving it as antivirusupdate.sh

with this in


#! bin/bash
/usr/bin/freshclam

I dont know how to go about making a logfile for this and writing to it.

Also is that all I have to do?

TIA

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Close…

<quote>
#!/bin/bash

#Notice the added ‘/’ in the line above… definitely needed.

FRESHCLAMLOG=/var/log/freshclam.log #change as needed

echo date +%s >> $FRESHCLAMLOG
echo ‘Attempting to start /usr/bin/freshclam…’ >> $FRESHCLAMLOG
/usr/bin/freshclam
if $? = 0 ] ; then
echo ‘No errors returned.’ >> $FRESHCLAMLOG
else
echo ‘Something may have gone wrong.’ >> $FRESHCLAMLOG
fi
echo ‘Cron job attempt ending.’ >> $FRESHCLAMLOG

</quote>

Obviously this may be more-verbose than you’d like it to be, but it’s
something to get you going. I have not verified the syntax at all but
imagine it’s fairly close. If you get error post back and we’ll clean
it up if needed.

Good luck.

BishopVLE wrote:
> I have never done a cron before so just want to check how to do it
> properly. I need to do this daily
> What I want to do is run /usr/bin/freshclam then if posible write
> something to a file with a time stamp that says this has been done.
>
> Is it as simple as going to /etc/cron.daily creating a new file and
> saving it as antivirusupdate.sh
>
> with this in
> Code:
> --------------------
>
> #! bin/bash
> /usr/bin/freshclam
> --------------------
>
>
> I dont know how to go about making a logfile for this and writing to
> it.
>
> Also is that all I have to do?
>
> TIA
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFJgHCv3s42bA80+9kRAgGRAJ4igGXScWb6Dbimq7tL3260HzEZOQCePIUz
8NhG+2IUFtyl9cDl/gBFmSg=
=iRms
-----END PGP SIGNATURE-----

Thanks, I have done as you said. How do I try to test this? I have gone to the termial and tried to run the script as root /etc/cron.daily/antivirusupdate.sh
but i get a error permission denied.

Or will i have to wait till suse tries to run the script

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

chmod +x ./yourScript.sh

Good luck.

BishopVLE wrote:
> Thanks, I have done as you said. How do I try to test this? I have gone
> to the termial and tried to run the script as root
> /etc/cron.daily/antivirusupdate.sh
> but i get a error permission denied.
>
> Or will i have to wait till suse tries to run the script
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFJgJYR3s42bA80+9kRAudMAJ96KU424JhGE+R2RljlhCnEBqJMSwCeKmQi
In2jGKY/kn1hTcGFd8qeyGA=
=kIGg
-----END PGP SIGNATURE-----

Thanks thaqt works a treat. i got concerned the other day when i tried running it more than once a day it through up a error.
But if i just leave it to its own devices it seams to be fine.

After looking at the log, in the bit that displayes.
echo date +%s >> $FRESHCLAMLOG

The date does not make sence. I have 1233308701 and 1233758702 is there a way to display this as a proper date and time?

Hi
I use in my scripts;


`date +\%m%d%y%H%M%S`

Have a look at the man page for date.


Cheers Malcolm °¿° (Linux Counter #276890)
openSUSE 11.1 x86 Kernel 2.6.27.7-9-default
up 23:44, 3 users, load average: 0.22, 0.08, 0.07
GPU GeForce 6600 TE/6200 TE - Driver Version: 180.22

As an alternative you could log to the syslog (/var/log/messages). This can be done using the logger program e.g.

logger -p cron.info “Attempting to start /usr/bin/freshclam”

this will create a log entry in the syslog like this:

Feb 4 21:17:11 suse1 andy: Attempting to start /usr/bin/freshclam

Cheers

Hmm, you realise that freshclam is usually run as a daemon from the script /etc/init.d/freshclam to update the database every 3 hours or so (IIRC). It will even poke clamd to tell it that the virus definitions have been updated. So you don’t need to write your own job for it, just start the freshclam service and make sure it’s enabled at boot.

On Wed February 4 2009 04:26 pm, ken yap wrote:

>
> BishopVLE;1934984 Wrote:
>> I have never done a cron before so just want to check how to do it
>> properly. I need to do this daily
>> What I want to do is run /usr/bin/freshclam then if posible write
>> something to a file with a time stamp that says this has been done.
>>
>> Is it as simple as going to /etc/cron.daily creating a new file and
>> saving it as antivirusupdate.sh
>>
>> with this in>
> Code:
> --------------------
> > >
> > #! bin/bash
> > /usr/bin/freshclam
> --------------------
>> >
>>
>> I dont know how to go about making a logfile for this and writing to
>> it.
>>
>> Also is that all I have to do?
>>
>> TIA
>
> Hmm, you realise that freshclam is usually run as a daemon from the
> script /etc/init.d/freshclam to update the database every 3 hours or so
> (IIRC). It will even poke clamd to tell it that the virus definitions
> have been updated. So you don’t need to write your own job for it, just
> start the freshclam service and make sure it’s enabled at boot.
>
>
BishopVLB;
In addition to Ken’s comment, you can configure freshclam,
via: /etc/freshclam.conf, to write to a log file with a time stamp. A typical
log entry would look like:


Wed Feb  4 05:28:23 2009 -> Received signal: wake up
Wed Feb  4 05:28:23 2009 -> Max retries == 5
Wed Feb  4 05:28:23 2009 -> ClamAV update process started at Wed Feb  4
05:28:23 2009
Wed Feb  4 05:28:23 2009 -> Using IPv6 aware code
Wed Feb  4 05:28:23 2009 -> Querying current.cvd.clamav.net
Wed Feb  4 05:28:23 2009 -> TTL: 900
Wed Feb  4 05:28:23 2009 -> Software version from DNS: 0.94.2
Wed Feb  4 05:28:23 2009 -> main.cvd version from DNS: 49
Wed Feb  4 05:28:23 2009 -> main.cld is up to date (version: 49, sigs: 437972,
f-level: 35, builder: sven)
Wed Feb  4 05:28:23 2009 -> daily.cvd version from DNS: 8950
Wed Feb  4 05:28:23 2009 -> Retrieving
http://db.us.clamav.net/daily-8950.cdiff
Wed Feb  4 05:28:23 2009 -> Trying to download
http://db.us.clamav.net/daily-8950.cdiff (IP: 207.57.106.31)
Wed Feb  4 05:28:25 2009 -> Downloading daily-8950.cdiff [100%]
Wed Feb  4 05:28:25 2009 -> cdiff_apply: Parsed 4619 lines and executed 4619
commands
Wed Feb  4 05:28:25 2009 -> daily.cld updated (version: 8950, sigs: 72593,
f-level: 38, builder: ccordes)
Wed Feb  4 05:28:25 2009 -> Database updated (510565 signatures) from
db.us.clamav.net (IP: 207.57.106.31)
Wed Feb  4 05:28:25 2009 -> Clamd successfully notified about the update.
Wed Feb  4 05:28:25 2009 -> --------------------------------------


P. V.
“We’re all in this together, I’m pulling for you.” Red Green