Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 5 Jul 2004 16:01:46 +0100
From:      Matthew Seaman <m.seaman@infracaninophile.co.uk>
To:        Taulant Galimuna <taulant@ipko.net>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: cron.daily and cron.hourly
Message-ID:  <20040705150146.GA40808@happy-idiot-talk.infracaninophile.co.uk>
In-Reply-To: <060b01c4629e$b60e45c0$0302a8c0@webmaster2>
References:  <20040704071004.E11E8AE097@nezlok.unixathome.org> <060b01c4629e$b60e45c0$0302a8c0@webmaster2>

next in thread | previous in thread | raw e-mail | index | archive | help

--qMm9M+Fa2AknHoGS
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Mon, Jul 05, 2004 at 04:45:27PM +0200, Taulant Galimuna wrote:

> I had a problem with my web-server that I already solved. But now I have =
to
> execute a PHP file on my FreeBSD server every hour, to get the needed
> updates from database.
>=20
> I know I need a shell script to execute that file and have to put this
> script to some directory that would execute it every hour.
>=20
> In linux it is appeared to be at /etc/cron.hourly
>=20
>=20
> but in FreeBSD I can't locate it.

There isn't anything like cron.hourly under FreeBSD.  (There is
/etc/periodic for running system maintenance tasks, but that runs at
most daily.)

What you need to do is run your script out of the crontab of the
appropriate user.  Since this is all web related I'm going to use
use 'www' as an example.

First, read the crontab(5) man page (ie. type 'man 5 crontab' -- if
you just type 'man crontab' you'll get the crontab(1) man page, which
is worth reading as well)

Then to set up the cron job, as root do:

    # crontab -e -u www

which will plunk you into an editor opened on the www users' crontab
file.  Add a line like:

    @hourly       /your/php/script/here

If that script generates any output to stdout or stderr, it will be
e-mailed to the www user.  Supposing you don't want that, either
redirect all output to /dev/null:

    @hourly       /your/php/script/here >/dev/null 2>&1

or use the MAILTO=3D variable as described in crontab(5).  Also note
that lots of people come adrift the first time the use cron(8) because
cron doesn't set up the environment like a login session.  In
particular, make sure that you explicitly set the $PATH at the top of
your script, or you will get a load of "command not found" errors.

	Cheers,

	Matthew


--=20
Dr Matthew J Seaman MA, D.Phil.                       26 The Paddocks
                                                      Savill Way
PGP: http://www.infracaninophile.co.uk/pgpkey         Marlow
Tel: +44 1628 476614                                  Bucks., SL7 1TH UK

--qMm9M+Fa2AknHoGS
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (FreeBSD)

iD8DBQFA6W1aiD657aJF7eIRAnH0AJ4wPAYGGs3o5TmlPyQtGZQO63aP2QCeKp56
K3uvCfEOVLlpvQfFLRg+NdM=
=4bZT
-----END PGP SIGNATURE-----

--qMm9M+Fa2AknHoGS--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040705150146.GA40808>