Yii Framework Forum: Creating A Cron Job That Runs Every 2 Minutes - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Creating A Cron Job That Runs Every 2 Minutes Rate Topic: -----

#1 User is offline   jr_jags 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 38
  • Joined: 05-November 12
  • Location:Philippines

Posted 01 February 2013 - 12:07 AM

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/?
0

#2 User is offline   Luke Jurgs 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 162
  • Joined: 16-October 11
  • Location:Australia

Posted 01 February 2013 - 03:01 AM

*/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.


View Postjr_jags, on 01 February 2013 - 12:07 AM, said:

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/?

0

#3 User is offline   jr_jags 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 38
  • Joined: 05-November 12
  • Location:Philippines

Posted 01 February 2013 - 05:31 AM

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

#4 User is offline   Luke Jurgs 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 162
  • Joined: 16-October 11
  • Location:Australia

Posted 01 February 2013 - 06:36 PM

What happens when you execute the full command:

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


as root?

View Postjr_jags, on 01 February 2013 - 05:31 AM, said:

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

0

#5 User is offline   jr_jags 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 38
  • Joined: 05-November 12
  • Location:Philippines

Posted 03 February 2013 - 09:21 PM

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
0

#6 User is offline   Luke Jurgs 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 162
  • Joined: 16-October 11
  • Location:Australia

Posted 03 February 2013 - 10:12 PM

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.


View Postjr_jags, on 03 February 2013 - 09:21 PM, said:

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

1

#7 User is offline   jr_jags 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 38
  • Joined: 05-November 12
  • Location:Philippines

Posted 05 February 2013 - 05:27 PM

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?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users