Re[2]: [PHP] Make cron file
| From: | Tom Rogers | Date: | Wed, 29 Sep 2004 02:44:48 +0000 |
| Subject: | Re[2]: [PHP] Make cron file | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-198143@lists.php.net to get a copy of this message | ||
Hi,
Wednesday, September 29, 2004, 1:18:20 AM, you wrote:
JB> [snip]
JB> I need make a cron file, for example a .job file:
JB> #mi ho di me seq job comment
JB> 45 11 * * 0-5 php -q /home/test/test.php # Make backup
JB> How can make it?.
JB> [/snip]
JB> Type crontab -e and the cron file will be opened....unless you're on a
JB> Windows machine....
JB> --
JB> PHP General Mailing List (http://www.php.net/)
JB> To unsubscribe, visit: http://www.php.net/unsub.php
You can do something like this for the web server user:
<?php
//new command to add
$cmd = '40 * * * * /usr/local/apache/bin/clearopensmtp 2>&1 > /dev/null';
//get existing cron entries
exec('crontab -l',$list);
//add new command
$list[] = $cmd;
//may need to change the server var for your setup
$path = dirname($_SERVER['PATH_TRANSLATED']).'/cronout';
//create a cronfile
if($fp = fopen($path,"w")){
foreach($list as $line){
$line = trim($line);
fputs($fp,$line."\n");
}
fclose($fp);
}
//tell cron about it
exec("crontab $path");
?>
Note appending to an existing cron file probably will not work as cron
has to be told to re read it and the webserver user can not do that
usually.
--
regards,
Tom