Cron 作业错误“无法打开输入文件”

发布于 2024-11-19 16:12:38 字数 1175 浏览 2 评论 0原文

我花了整整一天的时间寻找这种特定情况的解决方案(在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

莳間冲淡了誓言ζ 2024-11-26 16:12:38

这对游戏来说太晚了,但我确实找到了解决方案。发生的情况是:

我最初在 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.

甜是你 2024-11-26 16:12:38

试试这个:

* * * * * cd /var/www/html/cron/; /usr/bin/php /var/www/html/cron/filename.php -q -f

Try this:

* * * * * cd /var/www/html/cron/; /usr/bin/php /var/www/html/cron/filename.php -q -f
随风而去 2024-11-26 16:12:38
* * * * * /usr/bin/php -q /opt/app/current/record_user_login.php

尝试添加 -q 标志。另外,如果您还没有记录您的输出,这可能会很有帮助。

您确定您的 PHP 路径正确吗?我见过简单地执行此操作的示例:

* * * * * php -q /opt/app/current/record_user_login.php

您可能想尝试一下。

* * * * * /usr/bin/php -q /opt/app/current/record_user_login.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:

* * * * * php -q /opt/app/current/record_user_login.php

You may want to give that a try.

傾城如夢未必闌珊 2024-11-26 16:12:38

在 cpanel 中这个解决了我的问题

 php -q -f /home/skat_2347/public_html/cron.php /home/skat_2347/public_html/

In cpanel this one solve my problem

 php -q -f /home/skat_2347/public_html/cron.php /home/skat_2347/public_html/
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文