Answers.Body: <p>Is the user "admin" defined in Drupal? If not some commands will not fire under cv. cv needs a user under "username" that is recognized by Drupal as having the rights to fire the command you're interested in. I had this same issue myself which was fixed by identifying an authorized Drupal user.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-28T05:04:38.263Z
Answers.Text: Admin is defined in my case but that would probably be an issue for a lot of other people.
Answers.UserDisplayName: tanbog
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-27T20:27:58.180Z
Answers.LastActivityDate: 2018-11-27T20:27:58.180Z
Answers.UserDisplayName: Stephen Sloan
Answers.Body: <p>Ok so this may seem like a silly issue to some but after some messing around I figured out cron didn't have access to the path where CV was installed so to fix it the crontab entry had to be changed to:</p>
  
  <pre><code>*/5 * * * * /usr/local/bin/cv api job.execute --user=admin --cwd=/var/www/html/siteroot
  </code></pre>
  
  <p>There was no error as the mailer deamon was not firing correctly so no error was being sent or logged. </p>
  
  <p>Cron does not generally have access to the path that a shell root user does, which is why running the command <code>cv</code> as root works just fine.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-27T20:39:15.427Z
Answers.Text: debug suggestions here: https://chat.civicrm.org/civicrm/pl/sq974fi5c783xgu5dyisb6a6gw (probably would have led you to same solution, might be good for next time). also useful if you want to understand why cron environment is different to interactive environment - https://serverfault.com/questions/698577/why-is-the-cron-env-different-from-the-users-env or `man 5 crontab`
Answers.UserDisplayName: Chris Burgess
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-27T20:40:51.663Z
Answers.Text: you probably want to NOT run your CiviCRM cron as the root user; it should run as the same system user as you usually run CiviCRM (eg httpd, www-data, or your web application run user). otherwise you'll end up with files owned by root which CiviCRM can't modify when running from web. see https://docs.civicrm.org/sysadmin/en/latest/setup/jobs/#choosing-an-os-user
Answers.UserDisplayName: Chris Burgess
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-28T05:06:16.627Z
Answers.Text: I did not understand cron's environment at all - which is why I got confused. That was a very informative link thank you.
Answers.UserDisplayName: tanbog
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-27T05:06:36.897Z
Answers.LastActivityDate: 2018-11-28T05:08:11.690Z
Answers.LastEditDate: 2018-11-28T05:08:11.690Z
Answers.UserDisplayName: tanbog
Body: <p>I am attempting to use <a href="https://github.com/civicrm/cv" rel="nofollow noreferrer">CV</a> to call job.execute to run my scheduled tasks as described in the CiviCRM <a href="https://docs.civicrm.org/sysadmin/en/latest/setup/jobs/" rel="nofollow noreferrer">Documentation</a>. I am using Drupal 7. I have several independent sites running on the server. </p>
  
  <p>It works fine when I call it manually (for each site):</p>
  
  <pre><code>sudo cv api job.execute --user=admin --cwd=/var/www/html/siteroot
  </code></pre>
  
  <p>The tasks also work when I call them manually from the UI (for all sites)</p>
  
  <p>Crontab is set up with the following:</p>
  
  <pre><code>*/5 * * * * cv api job.execute --user=admin --cwd=/var/www/html/siteroot
  </code></pre>
  
  <p>the syslog shows no problems and that the cron fires (example output):</p>
  
  <pre><code>Nov  1 10:15:01 live CRON[8991]: (root) CMD (cv api job.execute --user=admin --cwd=/var/www/html/siteroot)
  </code></pre>
  
  <p>However,</p>
  
  <p>the scheduled tasks appear to not be running. I have configured several to run "whenever cron is run" but they still do not run unless I fire them manually.  </p>
  
  <p>Is there something I am missing? Is there a log in Civi where I can see if the command is being received?</p>
  
  <p>I am using Drupal 7, php7.0, CiviCRM 5.3 on Ubuntu 16.04</p>
  
Tags: <cron-job><scheduled-job><cv><sysadmin>
Title: CV Scheduled jobs not firing from cron
ThreadText: # CV Scheduled jobs not firing from cron
  
  (Asked by: username_0 on 2018-10-31)
  
  I am attempting to use CV to call job.execute to run my scheduled tasks as described in the CiviCRM Documentation. I am using Drupal 7. I have several independent sites running on the server. 
  It works fine when I call it manually (for each site):
  sudo cv api job.execute --user=admin --cwd=/var/www/html/siteroot
  
  The tasks also work when I call them manually from the UI (for all sites)
  Crontab is set up with the following:
  */5 * * * * cv api job.execute --user=admin --cwd=/var/www/html/siteroot
  
  the syslog shows no problems and that the cron fires (example output):
  Nov  1 10:15:01 live CRON[8991]: (root) CMD (cv api job.execute --user=admin --cwd=/var/www/html/siteroot)
  
  However,
  the scheduled tasks appear to not be running. I have configured several to run "whenever cron is run" but they still do not run unless I fire them manually.  
  Is there something I am missing? Is there a log in Civi where I can see if the command is being received?
  I am using Drupal 7, php7.0, CiviCRM 5.3 on Ubuntu 16.04
  
  **Tags:** cron-job, scheduled-job, cv, sysadmin
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2018-11-27. Score: 4 | Accepted answer
  
  Ok so this may seem like a silly issue to some but after some messing around I figured out cron didn't have access to the path where CV was installed so to fix it the crontab entry had to be changed to:
  */5 * * * * /usr/local/bin/cv api job.execute --user=admin --cwd=/var/www/html/siteroot
  
  There was no error as the mailer deamon was not firing correctly so no error was being sent or logged. 
  Cron does not generally have access to the path that a shell root user does, which is why running the command cv as root works just fine.
  
  > **Comments:**
  > **username_2**: debug suggestions here: https://chat.civicrm.org/civicrm/pl/sq974fi5c783xgu5dyisb6a6gw (probably would have led you to same solution, might be good for next time). also useful if you want to understand why cron environment is different to interactive environment - https://serverfault.com/questions/698577/why-is-the-cron-env-different-from-the-users-env or `man 5 crontab`  
  > **username_2**: you probably want to NOT run your CiviCRM cron as the root user; it should run as the same system user as you usually run CiviCRM (eg httpd, www-data, or your web application run user). otherwise you'll end up with files owned by root which CiviCRM can't modify when running from web. see https://docs.civicrm.org/sysadmin/en/latest/setup/jobs/#choosing-an-os-user  
  > **username_0**: I did not understand cron's environment at all - which is why I got confused. That was a very informative link thank you.  
  
  ---
  
  ### Answer by username_1 on 2018-11-27. Score: 1
  
  Is the user "admin" defined in Drupal? If not some commands will not fire under cv. cv needs a user under "username" that is recognized by Drupal as having the rights to fire the command you're interested in. I had this same issue myself which was fixed by identifying an authorized Drupal user.
  
  > **Comments:**
  > **username_0**: Admin is defined in my case but that would probably be an issue for a lot of other people.  
  
  ---
  
  