Creating A Cron Job That Runs Every 2 Minutes

Ive created a cron task at my commands folder named CronCommand.php

and I try executing that particular code on my terminal using pathtomyprotectedfolder/ .yiic Cron

and it executes smoothly, but when I want to run it by schedule and put it inside my crontab file at /etc/crontab It didnt work.

This is my code at crontab.

*/2 * * * * /usr/bin/php /var/www/AddressBook/addBook/protected/./yiic Cron cron >/dev/null

I want to run it every 2 minutes, Am I doing the right syntax? Im using Linux, and Is there a way to execute this command every 2 minutes without writing inside the crontab file at my etc/crontab/?


*/2 * * * * /usr/bin/php /var/www/AddressBook/addBook/protected/yiic Cron >/dev/null

Should be all that is required, make sure that the user that the cron job runs as has the correct privileges to access the script.

yes, Im using a root user in linux and the permissions are ok, but still it didnt execute

What happens when you execute the full command:


/usr/bin/php /var/www/AddressBook/addBook/protected/yiic Cron >/dev/null

as root?

Oh, I solved the problem, I just change the user to root just like this:

*/2 * * * * root /var/www/AddressBook/addBook/protected/yiic Cron >/dev/null

Ok you are using /etc/crontab, you aren’t really meant to edit that file on most linux systems. You are meant to edit a user specific crontab but I suppose it doesn’t really matter if you want to run the script as root.

To do maintain crontabs correct you generally do:




crontab -e -u root



this opens the default editor with the crontab for the user specified with the -u command.

Ubuntu CronHowto

Covers it pretty well for Debian based distros.

Oh so thats it, Is there a way to execute my cron code without applying */2 * * * * root /var/www/AddressBook/addBook/protected/yiic Cron >/dev/null on my etc/crontab?