我无法(正确)运行 cron 作业。
我创建了一个调用 mail() 的(非常大,但精简为空)php 页面
<?
mail('my@email.com', 'subject', 'test');
mail('other@address.com', 'subject', 'test');
?>
然后我创建了运行该文件的 cron 作业。crontab -e 中的代码行如下:
12 0 * * * /opt/lampp/bin/php /opt/lampp/htdocs/atlantis/application/controllers/cron.php
如果我从终端运行命令 /opt/lampp/bin/php /opt/lampp/htdocs/atlantis/application/controllers/cron.php,我会收到一封发送给自己的电子邮件。但是,如果我从 cron 作业运行同一行,它就不起作用。
我的下一站是检查日志。我正在使用 sSMTP 运行 Ubuntu。
Apr 16 11:49:17 drew-Virtual crontab[4722]: (drew) END EDIT (drew) //EDITED CRON
//Calling cron.php file from terminal
Apr 16 11:49:31 drew-Virtual sSMTP[4791]: Creating SSL connection to host
Apr 16 11:49:32 drew-Virtual sSMTP[4791]: SSL connection using RSA_AES_128_CBC_SHA1
Apr 16 11:49:34 drew-Virtual sSMTP[4791]: Sent mail for drew@drew-Virtual (221 ip-173-201-180-143.ip.secureserver.net closing connection) uid=1000 username=drew outbytes=444
Apr 16 11:49:34 drew-Virtual sSMTP[4794]: Creating SSL connection to host
Apr 16 11:49:35 drew-Virtual sSMTP[4794]: SSL connection using RSA_AES_128_CBC_SHA1
Apr 16 11:49:37 drew-Virtual sSMTP[4794]: Sent mail for drew@drew-Virtual (221 ip-173-201-180-143.ip.secureserver.net closing connection) uid=1000 username=drew outbytes=454
//I successfully received 2 emails, one to my work account, one to my personal account
//Calling cron.php from cron
Apr 16 11:50:01 drew-Virtual cron[857]: (drew) RELOAD (crontabs/drew)
Apr 16 11:51:01 drew-Virtual CRON[4808]: (drew) CMD (/opt/lampp/bin/php /opt/lampp/htdocs/atlantis/application/controllers/chron.php)
Apr 16 11:51:01 drew-Virtual sSMTP[4810]: Creating SSL connection to host
Apr 16 11:51:02 drew-Virtual sSMTP[4810]: SSL connection using RSA_AES_128_CBC_SHA1
Apr 16 11:51:04 drew-Virtual sSMTP[4810]: Sent mail for drew@drew-Virtual (221 ip-173-201-180-143.ip.secureserver.net closing connection) uid=1000 username=drew outbytes=698
//I did not receive any emails
你可以看到它只尝试发送 1 封电子邮件,我认为它失败了,因为我从未收到它。但是,它并没有告诉我为什么失败,我也没有任何其他线索。我还注意到 cron 作业中的 outbytes 比命令行中的要大。
最后,php 文件对每个人都有完整的 rwx 权限。