CiviCRM includes a number of "Jobs" which process data and handle batch tasks "in the background". The available jobs are listed below, with a description of their purpose and required parameters. Your site / system administrator should review the available jobs, and determine which ones need to be run on a regular basis. These jobs can be configured and enabled from the Scheduled Jobs page (Administer > System Settings > Scheduled Jobs). Jobs can also be executed manually from this page. However, for most sites it is best to run the required jobs from the server command line, often as one or more automatically scheduled "cron" jobs.
A "run frequency" can be set for each enabled job, allowing you to configure a single "master" cron task to trigger ALL enabled CiviCRM jobs whose next run is due. For example, you may want to run the CiviMail mailing scheduler every time your master cron task runs (which might be once a minute). However, you only want the Address geocoder job to run once a day. You can enable both jobs, and set the run frequency for the mailing scheduler to "Every time cron job is run", while setting the frequency for the Address geocoded to "Daily".
To actually trigger all the enabled jobs in Scheduled Jobs you will have to set up a cron job on the server that does this. You can find out how below in the section "Command-line Syntax for Running Jobs".
Scheduled Jobs Editing Fields
The API fields are:
Again you'll need to read the API reference or check the documentation in the files themselves for details about available command parameters and their effects.
The result of this entry is a scheduled call to the API function defined by the fields. For example, if your fields were:
civicrm_api3 Activity get with parameter contact_id=352
The result would be a call to function civicrm_api3_activity_get ($params) in file civicrm/api3/Activity.php, where $params=array(contact_id->532).
You can explore APIs, actions, and parameters at the API explorer, which is included in your CiviCRM installation at yourwebsite.com/civicrm/api/explorer. An explanation and video tour of the API explorer is here. Once you have a working API call at the API explorer you can transfer the same API call, action, and parameters to create a new Scheduled Job that will carry out that same task automatically.
Command-line Syntax for Running Jobs
PHP cli method
This method requires a valid Username and Password (for a Drupal, Joomla or WordPress user who has adequate permissions for the job or jobs being run). Note: password requirement is being removed in 4.2.
To run ALL scheduled jobs that are Enabled and are due to run based on last run and run frequency:
To run a specific job (regardless of Enabled status or last run time):
For example, to run Greeting updater job which requires ct (contact type) and gt (greeting type) parameters
/usr/bin/drush -u 1 -r /path/to/drupal @sites civicrm-api job.execute auth=0 -y
(-u 1 means user 1)
You can run ALL scheduled jobs that are Enabled and are due to run based on last run and run frequency by invoking a URL with curl or wget. You can also invoke specific jobs via URL. This method requires a valid Username and Password (for a Drupal, Joomla or WordPress user who has adequate permissions for the job or jobs being run). It also requires you to pass in the CIVICRM_SITE_KEY which is configured by editing your copy of civicrm.settings.php (see Configuring your Site Key below).
Run ALL Scheduled Jobs via URL
Calling cron.php as shown below will run ALL scheduled jobs that are Enabled and are due to run based on last run and run frequency:
When calling these urls using wget from within a crontab, enclose the url in quotes, like so:
Run a Specific Job via URL
You can also run any single job via URL by passing job=<api_action> as well as any required parameters. For example to run the Update Greeting job via URL:
Running CiviCRM crons in Aegir
If you are using the Aegir hosting environment, with the provision_civicrm sub-module, you can automate the installation of a new cron for each site using the hosting_civicrm_cron module. You can also use the Drush method below to call CiviCRM cron tasks.
Running CiviCRM crons using Drush
You can run cron manually for a site by using the drush command:
This assumes that you have an administrator account called "admin" with the correct CiviCRM permissions.
Currently (CiviCRM 4.2.x) you need to use an additional argument, 'auth=0', to work around CRM-11199.
Configuring your Site Key
If you are triggering jobs using the URL method, you must manually generate a site key, and then add it to your CiviCRM settings file.
Depending on which version of CiviCRM you've installed, you may have this setting in your file already with a value of null, or you may need to add the line. In either case, replace null with the value of your key.
EXAMPLE: If my generated site key value is: 3cx4aNkpQwxmM1hTMV~!B09iO6
* Finally, make sure that you include the key=<sitekey> parameter whenever your run any of these scripts.
DB Error: Connect failed
The connect failed error message means that CiviCRM was not able to connect to the SQL database at all. The problem may be in connecting to the CiviCRM database OR with the Drupal/Joomla/WordPress database. If your CiviCRM installation is otherwise working, the most likely cause is the connection to the Drupal/Joomla/WordPress database, which is accessed much less frequently.
The most likely cause is incorrect username, password, or other settings in the civicrm.settings.php file. Carefully check the setting for define( 'CIVICRM_UF_DSN' - your setting may have been incorrect for some time and enabling the cron process is only now exposing the problem.
DB Error: no such table
A common cause of this problem is if your Drupal installation has a table prefix. To validate the connection, CiviCRM looks at the users table while initializing the cron job. The specific name of the users table is set in yourpath/civicrm/admin/setting/uf (or civicrm/administer/system settings/CMS database integration). If the users table name set there does not match the actual table name in your Drupal SQL database you will get the 'no such table' error. Check your Drupal table prefix in settings.php (usually in sites/default) - look for a setting like $db_prefix = 'dru_';. In yourpath/civicrm/admin/setting/uf change the "Drupal Users Table Name" to match–for instance, if your prefix is dru_, change the table name to dru_users.
Wrong permissions for cli.php
If you are running cli.php directly via cron job you may need to change permissions of cli.php to allow it to execute. Depending on how cron runs and the owner of cli.php you might try one of these options–or use your ftp program to change file permission for cli.php similarly:
chmod 744 cli.php [Gives owner execute permissions]
chmod 754 cli.php [Gives owner & group execute permissions]
chmod 755 cli.php [Gives everyone execute permissions]
Running cli.php via php (as recommended above) will also solve this problem. Use this:
php /your/directory/structure/sites/all/modules/civicrm/bin/cli.php -u user -p password -e Job -a execute
Rather than this:
/your/directory/structure/sites/all/modules/civicrm/bin/cli.php -u user -p password -e Job -a execute