Reputation: 1013
as part of a php-slim web application, in my init.php file I require a Crontab.php which contains the following code:
<?php
// clears any existing crontab jobs first
exec("crontab -r");
$ctCommand = '"*/1 * * * * php ./ProcessCycleTimeData.php"';
exec("(crontab -l 2>/dev/null; echo " . $ctCommand . " ) | crontab -");
exec("crontab -l");
?>
When I run the commands manually, the job gets added and I can see it being recorded, however it doesn't seem to run. However, when I run php ./ProcessCycleTimeData.php
it works fine. Any ideas where to troubleshoot this?
I'm looking into the error logs, and every minute I get the following log:
crontab: no crontab for daemon
Upvotes: 3
Views: 4235
Reputation: 1013
I managed to get it working. My solution was to check if the crontab was actually running by appending the crontab job with >>/tmp/auto-update.log 2>&1
which allowed me to further investigate the issue.
I found that the crontab was indeed running, but as a different user (hence why when I was manually calling crontab -e
I could not see the job since I am calling it as my own username.
The crontab was also actually invoking my PHP script, where I could then find out the errors in the auto-update.log
, which happened to be due to incorrectly stating the require paths.
Upvotes: 2
Reputation: 1003
You can use crontab -e
to edit the crontab, this will open your default editor (generally vi
if other is not set).
Edit the crontab for the user you need this script to run, and add a line as:
*/1 * * * * php ./ProcessCycleTimeData.php
This means
Every one minute
Upvotes: 2