-1

I have codeigniter cron jobs in controller in /data1/src/test1. I am running one of the methods in controller present in above code. so i run the cron as follows

30 08   *   *   * /usr/bin/php  /data2/src/test/index.php controller method1 > /tmp/test.log 2>&1.

Test folder is codeigniter framework and controller1.php is present in controllers folder.and method1 is function inside this controller class.

But when this cron runs.I get error in log file as permission denied. Please guide me for scheduling cron in codeigniter

Narf
  • 14,600
  • 3
  • 37
  • 66
  • 1
    How are you changing your cron? Normally it's set with `crontab -e`, not by editing the crontab directly. You can temporarily add a rule like the following, to check under what user your cron commands are executed: `* * * * * whoami >/tmp/who.txt` After a minute passes check the file. Then see if that user is in the right group to execute the file. When I add the above rule to my system it prints out my user name. – alexg Feb 08 '16 at 15:47
  • who.txt is showing root text.and the cron job which i have written in the post is also under root user –  Feb 08 '16 at 15:54
  • I assume you've checked the permissions of `index.php`? – alexg Feb 08 '16 at 15:59
  • And `/usr/bin/php`? Can it be run by root? – alexg Feb 08 '16 at 15:59
  • Wait a minute, where are you getting the error? Is that in a codeigniter log file? If so, this means that your script is executed with root permission. Perhaps your application is not built to be run by root and the permission error is some other thing. Maybe you're trying to open a file that is not accessible by root? Usually a codeigniter application would be executed as `www-data` or whatever your apache user is. – alexg Feb 08 '16 at 16:02
  • 1
    /bin/sh: 1: /usr/bin/php: Permission denied.This is the error in log file. –  Feb 08 '16 at 16:38
  • Does this answer your question? [Permission denied with bash.sh to run cron](https://stackoverflow.com/questions/21646551/permission-denied-with-bash-sh-to-run-cron) – tripleee Jul 26 '20 at 11:42

1 Answers1

2

The user under which the crontab runs doesn't have permissions to access /usr/bin/php.

"Fixing" it should be as simple as chmod +x /usr/bin/php.

Narf
  • 14,600
  • 3
  • 37
  • 66