Cron 作业错误“无法打开输入文件”
我花了整整一天的时间寻找这种特定情况的解决方案(在 Stack Overflow 和 Googs 上),所以如果这已经在 Stack Overflow 上,我深表歉意。
我正在尝试通过命令行在 AWS 中设置一个相当简单的 cron 作业:
* * * * * /usr/bin/php /opt/app/current/record_user_login.php
cron 作业成功触发并且能够访问有问题的文件(它正在访问正确的环境)。但是,我不断收到错误:
"Could not open input file"
我:
- chmod 将文件更改为 777
- 将脚本更改为仅回显“Hello world”
- 来启动 cronjob
- 尝试以 root 用户chmod 将 crontab 文件本身更改为 777
这些解决方案似乎都不起作用。由于未知的原因,我无法编辑 rsyslog.conf 来打开 cronlog,因此我没有任何数据。
record_user_login 的内容是:
<?
include("connect_to_mysql.php");
//Logged in in 1 week
$current_date = date('Y-m-j H:i:s', strtotime("-1 weeks"));
$query = "SELECT DISTINCT user_id FROM users_login_history WHERE sign_in_time > '$current_date'";
$result = mysql_query($query) or die(mysql_error());
$i = 0;
while($row = mysql_fetch_array($result)){
$i++;
}
$query = "INSERT INTO sqm_data (feature, action) VALUES ('user login', $i)";
if(!mysql_query($query)) {
die('Error: ' . mysql_error());
}
?>
Any ideas?
I've spent a solid day looking for a solution to this specific situation (on Stack Overflow and the Googs,) so I do apologize if this is already on Stack Overflow.
I'm trying to set up a fairly simple cron job in AWS via the command line:
* * * * * /usr/bin/php /opt/app/current/record_user_login.php
The cron job successfully fires and is able to touch the file in question (it is hitting the correct environment.) However, I keep getting the error:
"Could not open input file"
I've:
- chmod'd the file to 777
- Changed the script to just echo "Hello world"
- Tried initiating the cronjob as the root user
- chmod'd the crontab file itself to 777
None of these solutions seem to work. For a yet unknown reason, I can't edit rsyslog.conf to turn on cronlog, so I don't have any data from that.
The contents of record_user_login are:
<?
include("connect_to_mysql.php");
//Logged in in 1 week
$current_date = date('Y-m-j H:i:s', strtotime("-1 weeks"));
$query = "SELECT DISTINCT user_id FROM users_login_history WHERE sign_in_time > '$current_date'";
$result = mysql_query($query) or die(mysql_error());
$i = 0;
while($row = mysql_fetch_array($result)){
$i++;
}
$query = "INSERT INTO sqm_data (feature, action) VALUES ('user login', $i)";
if(!mysql_query($query)) {
die('Error: ' . mysql_error());
}
?>
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这对游戏来说太晚了,但我确实找到了解决方案。发生的情况是:
我最初在 Windows 记事本中输入了 cron 命令并上传了它们。显然发生的事情是回车符(“/r”,IIRC)被插入,我不知道(和vim,当我从putty查看文件时)。一位朋友用一种我不知道的方法删除了这些回车符不幸的是,回忆/并没有很好地遵循,但在退货被删除后,一切都奏效了。
This is absurdly late to the game, but I did find a solution to this. What was happening was:
I had originally typed up the cron commands in Windows Notepad and uploaded them. Apparently what was happening was a carriage return ("/r", IIRC) was getting plugged in, unbeknownst to me (and vim, when I viewed the file from putty.) A friend removed those carriage returns by a method I don't recall/did not follow too well unfortunately, but after the returns were removed, it all worked.
试试这个:
Try this:
尝试添加 -q 标志。另外,如果您还没有记录您的输出,这可能会很有帮助。
您确定您的 PHP 路径正确吗?我见过简单地执行此操作的示例:
您可能想尝试一下。
Try adding the -q flag. Also, it might be beneficial if you're not already, to log your output.
Are you sure your path to PHP is correct? I've seen examples that simply do this:
You may want to give that a try.
在 cpanel 中这个解决了我的问题
In cpanel this one solve my problem