cron-job未发送正确的日期



我有一个cronjob,当(管理)用户设置日期时会更新。cronjob的设置正确,因为它在cronjob列表中(在CPANEL上)显示:

lynx -source http://www.example.com/dynam_code/autoscripts/expenseClaims.php?do=notify&date=1350252000&final=1350338400

这是Cronjob创建脚本:

$output = shell_exec('crontab -l');
$jobs = explode(PHP_EOL,$output);
$minute = '00';
$hour = '09';
$day = date('j',strtotime($_GET['reminder']));
$month = date('n',strtotime($_GET['reminder']));
for($i = 0; $i < count($jobs); $i++) {
    if(strpos($jobs[$i],'http://intra.vceza.com/dynam_code/autoscripts/expenseClaims.php?do=notify') !== false)
        $jobs[$i] = $minute.' '.$hour.' '.$day.' '.$month.' * lynx -source http://intra.vceza.com/dynam_code/autoscripts/expenseClaims.php?do=notify&date='.strtotime($_GET['done']).'&final='.strtotime($_GET['approved']);
    }
    foreach($jobs as $key => $value) { 
        if($value == "") { 
            unset($jobs[$key]); 
        } 
    } 
    $jobs = array_values($jobs); 
    $jobs[] = "";
    $output = implode(PHP_EOL,$jobs);
    file_put_contents('/tmp/crontab.txt', $output);
    exec('crontab /tmp/crontab.txt',$output,$return);

这个cronjob触发了一个邮件脚本,该邮件根据这些日期将邮件发送给整个公司。当脚本自动运行时,它显示了所有日期为1970年1月1日。但是,当我从cron作业中复制到该php文件的路径并运行它时,它会发送正确的日期。

这是抓取日期并发送邮件的脚本:

if($_GET['do'] == 'notify') {
    $time = $_GET['date'];
    $day = date('l',$time);
    $date = date('j F Y',$time);
    $final = date('j F Y',$_GET['final']);
    $to = 'people@example.com';
    $str = "Expense Claims";
    $html_data = '<html><head><title>'.$str.'</title></head><body style="font-family:Calibri, Arial; font-size:15px">Good day all,<br/><br/>Please take note that all Expense Claim should be completed on the intraweb by ' . $day . ' morning <b>' . $date . ' before 9am.</b><br/><br/>All supervisors should approve claims by Friday morning <b>' . $final . ' before 9am.</b> <br/><br/>All slips and supporting documents should be handed in by Friday morning <b>' . $final . ' before 9am</b>. Bear in mind that it is the sole responsibility of the claimee to hand in his/her slips or supporting documents.<br/><br/><span style="color:red">Please take note that Expense Claims will only reach the Finance Department if <b>submitted and approved on time.</b> Claims not submitted or approved on time will only be processed in the following month.</span><br /><br/>Kind regards,<br/>JD</body></html>';
    $mime = new MIME_mail("John Doe <jd@example.com>", $to, $str);
    $mime->fattach($path,"",OCTET,BASE64,ATTACH);
    $mime->attach($html_data,$str, HTML, BASE64);
    $mime->send_mail();
}

我不知道问题是什么,我尝试查看代码。就像我说的那样,如果我手动运行它,则可以正常运行。如果Cronjob运行它,则不会。

您的crontab条目包含一个'&amp;'do = notify之后。如果您使用'&amp;'在cron作业的命令中(或此事 *nix shell),这意味着&amp; amp; amp;将在后台执行。因此,仅执行'lynx -source http://www.example.com/dynam_code/autoscripts/expenseclaims.php?do=notify'部分。您需要引用URL,因此命令看起来像这样:

lynx -source 'http://www.example.com/dynam_code/autoscripts/expenseClaims.php?do=notify&date=1350252000&final=1350338400'

相关内容

  • 没有找到相关文章

最新更新