<?php
// multiple recipients
$to = '[email protected]' . ', '; // note the comma
$to .= '[email protected]';// subject
$subject = 'Birthday Reminders for August';// message
$message = '
<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<p>Here are the birthdays upcoming in August!</p>
<table>
<tr>
<th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
<td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
</tr>
<tr>
<td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>
';// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";// Additional headers
$headers .= 'To: Mary <[email protected]>, Kelly <[email protected]>' . "\r\n";
$headers .= 'From: Birthday Reminder <[email protected]>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";
$headers .= 'Bcc: [email protected]' . "\r\n";// Mail it
mail($to, $subject, $message, $headers);
?>
// multiple recipients
$to = '[email protected]' . ', '; // note the comma
$to .= '[email protected]';// subject
$subject = 'Birthday Reminders for August';// message
$message = '
<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<p>Here are the birthdays upcoming in August!</p>
<table>
<tr>
<th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
<td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
</tr>
<tr>
<td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>
';// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";// Additional headers
$headers .= 'To: Mary <[email protected]>, Kelly <[email protected]>' . "\r\n";
$headers .= 'From: Birthday Reminder <[email protected]>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";
$headers .= 'Bcc: [email protected]' . "\r\n";// Mail it
mail($to, $subject, $message, $headers);
?>
合法值minute
00-59hour
00-23,其中00点就是晚上12点day-of-month
01-31month-of-year
01-12day-of-week
0-6,其中周日是0这样用户就可以往crontab 文件中写入无限多的行以完成无限多的命令。命令域中可以写入所有可以在命令行写入的命令和符号,其他所有时间域都支持列举,也就是域中可以写入很多的时间值,只要满足这些时间值中的任何一个都执行命令,每两个时间值中间使用逗号分隔。除了数字还有几个个特殊的符号就是”*”、”/”和”-”、”,”,*代表所有的取值范围内的数字,”/”代表每的意思,”*/5″表示每5个单位,”-”代表从某个数字到某个数字,”,”分开几个离散的数字。几个例子:每天早上6点0 6 * * * echo “Good morning.” >> /tmp/test.txt //注意单纯echo,从屏幕上看不到任何输出,因为cron把任何输出都email到root的信箱了。每两个小时0 */2 * * * echo “Have a break now.” >> /tmp/test.txt晚上11点到早上8点之间每两个小时,早上八点0 23-7/2,8 * * * echo “Have a good dream:)” >> /tmp/test.txt每个月的4号和每个礼拜的礼拜一到礼拜三的早上11点0 11 4 * 1-3 command line1月1日早上4点0 4 1 1 * command lineSHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root //如果出现错误,或者有数据输出,数据作为邮件发给这个帐号
HOME=/ //使用者运行的路径,这里是根目录
# run-parts
01 * * * * root run-parts /etc/cron.hourly //每小时执行/etc/cron.hourly内的脚本
02 4 * * * root run-parts /etc/cron.daily //每天执行/etc/cron.daily内的脚本
22 4 * * 0 root run-parts /etc/cron.weekly //每星期执行/etc/cron.weekly内的脚本
42 4 1 * * root run-parts /etc/cron.monthly //每月去执行/etc/cron.monthly内的脚本大家注意”run-parts”这个参数了,如果去掉这个参数的话,后面就可以写要运行的某个脚本名,而不是文件夹名了。[例8]5,15,25,35,45,55 16,17,18 * * * command这就是表示任意天任意月,其实就是每天的下午4点、5点、6点的5 min、15 min、25 min、35 min、45 min、55 min时执行命令。[例9] 在每周一,三,五的下午3:00系统进入维护状态,重新启动系统。那么在crontab 文件中就应该写入如下字段:00 15 * * 1,3,5 shutdown -r +5然后将该文件存盘为foxy.cron,再键入crontab foxy.cron安装该文件。[例10] 每小时的10分,40分执行用户目录下的innd/bbslin这个指令:10,40 * * * * innd/bbslink[例11] 每小时的1分执行用户目录下的bin/account这个指令:1 * * * * bin/account[例12] 每天早晨三点二十分执行用户目录下如下所示的两个指令(每个指令以;分隔):20 3 * * * (/bin/rm -f expire.ls logins.bad;bin/expire$#@62;expire.1st)[例13] 每年的一月和四月,4号到9号的3点12分和3点55分执行/bin/rm -f expire.1st这个指令,并把结果添加在mm.txt这个文件之后(mm.txt文件位于用户自己的目录位置)。12,55 3 4-9 1,4 * /bin/rm -f expire.1st$#@62;$#@62;mm.txt[例14] 我们来看一个超级用户的crontab文件:#Run the ‘atrun’ program every minutes#This runs anything that’s due to run from ‘at’.See man ‘at’ or ‘atrun’.0,5,10,15,20,25,30,35,40,45,50,55 * * * * /usr/lib/atrun40 7 * * * updatedb8,10,22,30,39,46,54,58 * * * * /bin/sync
或者写一个守护进程来实现
while()
{
sleep();//用这个函数来等待,不过长时间运行不知道会不会很快被php.ini里面的内存限制给杀死
}
不行就c/c++写一个 语法都差不多,用现成控件也不是什么难事