Cron Job error “Could not open input file”

cron

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?

Best Answer

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.

Related Topic