• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CLI call behaves incorrectly when called from cron, yet works fine from command line

CI 2.1.2 installed.
From the command line, I can run
php /home/myusername/public_html/mysite/index.php cron_jobs

It works as expected, executing the cron_jobs controller. Yet, when this statement is moved over to cron like so
*/1 * * * * php /home/myusername/public_html/mysite/index.php cron_jobs
The line gets executed as if there is no "cron_jobs" controller argument. The default controller's HTML gets emailed by cron, indicating that it was executed instead.

Am I doing it wrong? My cron tasks worked using file_get_contents() in 1.7.2, prior to attempting the new CLI-style way of calling the controller.

Edit: I have already considered http://stackoverflow.com/questions/77984...ntab-entry and tried including different absolute paths to php (/usr/bin/php and also /usr/local/bin/php)

This is solved with a wrapper script that the cron job called (rather than having the cron job call php directly).

On my CentOS server, the PHP wrapper script needs some environment variables set up, such as terminal type. Here is the wrapper script that cron calls:

/usr/bin/env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin COLUMNS=72 /usr/local/bin/php -c /usr/local/lib/php.ini /path/to/code/index.php cron_jobs

Thanks to John S, the Linux admin at HostGator who provided this solution.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.