Reputation: 5819
i need to set a crontab from a php script. i know that it can be set by
system("echo '* * * * * echo \"Hello world\"' >> cron.crontab"); system("crontab cron.crontab"); //cron.crontab is the file name of the crontab
"cron.crontab" file is created in root directory, but crontab is not working as expected! when i try the following command, it says that no crontab is set!
crontab -l
i think i am missing something. i am using yii framework. is there an extension to handle cron in yii framework? is there any other way to do it? Please help me. Thanks.
Upvotes: 2
Views: 858
Reputation: 86506
Apache generally isn't going to be able to muck around with the main crontab. However, each user has a crontab as well, and it's quite likely that your code above is setting apache
's crontab (or the crontab for whatever user your site runs as).
Try crontab -u apache -l
, or replace apache
with whatever user your site runs as, and see if the entries you set are there.
Upvotes: 2
Reputation: 117417
Are you running crontab -l
as the same user as the web server is running under? Otherwise you won't see its cronjobs.
Upvotes: 2
Reputation: 6570
You generally have to be root to set the crontab, and it's unlike that php is running as root, in which case you're out of luck.
Edit: Not completely out of luck. See the link in Sebastian's comment above.
Upvotes: 0