I use cron to execute some php scripts (owncloud background tasks etc). My server runs nginx and PHP via php-fpm, which by default runs PHP processes under the apache
user, the only user with write access to /var/www
aside from root. Thus it should be fine to add these background jobs to apache`s crontab:
crontab -u apache -e
The contents:
MAILTO=cron@localhost
* * * * * echo "..." | mail -s "crontest" cron@localhost
This should send me a mail every minute, however it does not. When I run the command as the apache user (sudo -s -u apache
), it works fine, but the cronjob never executes.
I found some mention of "locked accounts" here, but I'm not sure if the suggested solution is a good idea.
Best Answer
I don't believe that the number 60 is valid in the minutes column (someone correct me if I'm wrong). The number should be between 0 and 59.
What you're actually telling the machine to do is "run
echo "..." | mail -s "crontest" cron@localhost
every 60 minutes". If you want the job to run every minute, the line would be:*/1 * * * * echo "..." | mail -s "crontest" cron@localhost
http://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/