开发者

Cron Job error "Could not open input file"

I've spent a solid day looking for a solution to this specific situatio开发者_JS百科n (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?


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:

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


* * * * * /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.


In cpanel this one solve my problem

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜