-1

I am using core PHP and written a simple script that needs to be called automatically. For testing purpose I have just written a print statement as below,

$host = 'localhost';
$user = 'admin';
$pass = 'password';
$db = 'TestDB';
print ($user);

When I execute the script from the command line as below, it works fine

php /Applications/MAMP/htdocs/project/services/test.php > ~/cronOutput/test.txt 

But when I call this from Cron, its not at all getting called. Below is the crontab command that I have,

* * * * * /usr/bin/php /Applications/MAMP/htdocs/project/services/test.php > ~/cronOutput/test.txt 
* * * * * php /Applications/MAMP/htdocs/project/services/test.php > ~/cronOutput/test.txt

Both the commands above does not work.

Gerald Schneider
  • 26,582
  • 8
  • 65
  • 97

1 Answers1

0

I found the issue here. If you are no the root user, you must create a new crontab file with the specific user name. I was logged in as a different user and was trying to run it from the root user and hence it was not working.

Below is the command to create a user specific crontab crontab -u your-user-name -e

Hope this helps someone!