FreeBSD automated daily script execution
August 22, 2007 (as amended)

This page details how to create a daily script for use with FreeBSD. A daily script can do a whole lot of work for you while you sleep, or whatever; they can be very useful. FreeBSD in fact runs a daily maintenance script already - the process below creates a separate daily script, for general purposes. The script below should also not be confused with a daily backup script which you may also run, although they could be combined.

The process below details how to start a PHP script from cron, each day. Then we can use PHP to do whatever we need to do in our daily event.

step 1. create the PHP script


Save the above script as /usr/home/adminuser/daily.php

step 2. schedule the PHP script

Schedule the daily event by adding the following lines to the end of root's crontab (this runs the script every day at 07:50):

# run the daily event at 7:50AM
50      07       *       *       *     /usr/local/bin/php /usr/home/adminuser/daily.php > /usr/home/adminuser/daily.txt 2>&1

And that's it! Every day at 07:50, your PHP script will run, in there you can do whatever you need to do, with full PHP functionality.