1
我有一個cronjob,當(管理)用戶設置一個日期時得到更新。該的cronjob設置正確,因爲它顯示了這樣的的cronjob列表(在的cPanel):Cron-job不發送正確的日期
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 = '[email protected]';
$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 <[email protected]>", $to, $str);
$mime->fattach($path,"",OCTET,BASE64,ATTACH);
$mime->attach($html_data,$str, HTML, BASE64);
$mime->send_mail();
}
我不知道是什麼問題,我試圖尋找通過代碼。就像我說的那樣,如果我手動運行,它就可以工作。如果cronjob運行它,它不會。
你真的看過你的crontab在創建後的樣子嗎?如果非cron調用有效,那麼cron的調用如果cron作業已正確輸入,也應如此。看起來'date'和'final'get vars的值是無效的,因爲php認爲它是0(從1970年1月1日開始)。 – Friek
我有。 crontab中的那行代碼被複制並粘貼到crontab中。在劇本更新之後,它就是這樣的節目。 – Albert
查看我的回答;) – Friek