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:
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?
The most common reason for Cron Jobs to not work are: Not-working script. Incorrect path/URL to file specified. Use of special characters.
What does * mean in Cron? The asterisk * is used as a wildcard in Cron. * sets the execution of a task to any minute, hour, day, weekday, or month.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With