在Putty命令行中我写
/usr/bin/php /var/www/html/folder/file.php
也php /var/www/html/folder/file.php
都给出'Could not open input file'
文件权限为777。操作系统为UNIX
PHP脚本:<?php
$headers = 'MIME-Version: 1.0' . "rn";
$headers .= 'Content-type: text/html; charset=utf-8' . "rn";
$headers .= 'From: CRON';
mail('admin@website.com','CRON',"<b>THIS IS SIMULATION TEST</b>",$headers);
?>
当您在PHP或cron文件中使用Windows换行符(rn)而不是Unix样式(n)时,有时会发生这种情况。
修复:将行尾转换为Unix样式
dos2unix /var/www/html/folder/file.php
或
sed -i 's/r//' /var/www/html/folder/file.php
或
使用编辑器如notepad++转换EOL:
- 用notepad++ 打开文件
- 双击右下角的Dos/Windows
- 更改为"UNIX/OSX格式"
- 保存、上传和测试
.
请记住,对于PHP文件和保存cron命令的文件都要这样做。
使用相对路径。也就是说,如果你cd到/var/www/html/文件夹并从那里运行它。