Reputation: 947
I'm trying to run my first cron job on MAC OS (my localhost is running MAMP).
To access crontab, to run a cron job, I'm typing the following into the command line:
crontab -e
Then I press i
on the keyboard to go into insert mode to insert the cron job.
The cron job inserted is
* * * * * wget http://localhost:8888/project/cron.php
Then I press esc
and type :wq
in the command line.
I then get a message:
installing new crontab
Then I check what cronjobs are running with crontab -l
and it says:
* * * * * wget http://localhost:8888/project/cron.php
But nothing happens...
On a separate note, below is the script I'm executing as a test script in the cron.php file. It is meant to generate a new time stamp in a text file in the root of the project (the cron job is supposed to make this happen every minute):
<?php
$file = dirname(__FILE__) . '/output.txt';
$data = "hello, it's " . date('d/m/Y H:i:s') . "\n";
file_put_contents($file, $data, FILE_APPEND);
?>
If anyone has any advice as to why this isn't working I'd be hugely grateful.
I've tried the steps shown above at both system level (i.e macmini) and also in my 'project' folder.
I'm completely new to all of this so any help would be amazing.
Upvotes: 2
Views: 1235
Reputation: 947
The solution to this was to use the file paths not the url. First I found where the php was located. I did this with:
whereis php
This gave me the following file path:
/usr/bin/php
I then got the FULL file path to the cron.php file in my project:
/Applications/MAMP/htdocs/project/cron.php
I then combined the two in the crontab cron job:
* * * * * /usr/bin/php /Applications/MAMP/htdocs/project/cron.php
The actual steps I used are the same as in my original question.
Upvotes: 2