| |||||||||||||
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 a shell script, which is in turn started automatically by FreeBSD each day. Then we can use PHP to do whatever we need to do in our daily event. The idea here is to write the daily event code in PHP, and simply use the shell script below to start it.
#!/bin/sh
#### daily script 1 - by Stuart Udall 2007 - http://www.blazingfibre.net/ ####
LOGFILE=/var/log/daily.log
# begin
echo "daily process started:" >> ${LOGFILE}
date >> ${LOGFILE}
# run our PHP script
/usr/local/bin/php /usr/home/adminuser/daily.php > /usr/home/adminuser/daily.txt
# exit
echo "daily process completed:" >> ${LOGFILE}
date >> ${LOGFILE}
<?php phpinfo(); ?>
Schedule the daily event by editing /etc/crontab and adding the following lines to the end of the file (this runs the script every day at 07:50):
# run the daily event 50 07 * * * root /usr/home/adminuser/daily.sh
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.
Notes:
|
related articles: |