Not Able To Run Consolecommand From Cron Tab

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 !

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.

[color="#006400"]/* moved from Bug Discussions */[/color]

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 !

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?