Yii Framework Forum: Not Able To Run Consolecommand From Cron Tab - Yii Framework Forum

Jump to content

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

Not Able To Run Consolecommand From Cron Tab Rate Topic: -----

#1 User is offline   riyazMuhammed 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 13-September 12
  • Location:Bangalore

Posted 18 March 2013 - 06:48 AM

Hi,

I have written a ConsoleCommand which runs awesome from Windows Command prompt and also linux terminal. My problem is that , when I add this command in the cron tab I get the following error when it is been executed.

This script must be run from the command line.

What could be the problem ?

PS: When I had register_argc_argv Off in my php.ini, I was not even able to run this command from terminal. When I turned it on, It started working from terminal but it is not at all working when I have it in crontab!

Please Help !
0

#2 User is offline   CeBe 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 480
  • Joined: 16-July 10
  • Location:Berlin. Germany

Posted 18 March 2013 - 07:48 AM

You need to make sure your cron command runs in the same environment as your terminal.
The same user.
Uses the same php binary and config.
Maybe some ENV variables are not set.
0

#3 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 18 March 2013 - 08:10 AM

/* moved from Bug Discussions */
"Less noise - more signal"
0

#4 User is offline   riyazMuhammed 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 13-September 12
  • Location:Bangalore

Posted 19 March 2013 - 03:06 AM

View PostCeBe, on 18 March 2013 - 07:48 AM, said:

You need to make sure your cron command runs in the same environment as your terminal.
The same user.
Uses the same php binary and config.
Maybe some ENV variables are not set.


Thanks So much @CeBe !

I used to run the command from cron as
php /home/pathtomyapp/console.php myCommand


Now I modified it to

/usr/local/bin/php /home/pathtomyapp/console.php myCommand


and that did it !
0

#5 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,013
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 19 March 2013 - 09:29 AM

I always wonder, why so many people use custom console.php or similar things when this is absolutely not neccessary. I mean, the steps to create a custom console command are really simple and described well in the documentation:

1. Create a class that extends from CConsoleCommand and put it into your protected/commands folder
2. Call the command from yiic in your protected directory: /path/to/my/project/protected/yiic myCommand

Why all the fuss?
1

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