Cron jobs are automated tasks executed by a server at scheduled intervals. Sugar relies on cron to perform time-based jobs like sending email reminders, processing workflow events, and monitoring forecast intervals, just to name a few. This article explains how to set up cron on the server where you host Sugar on site.
For more information on the default scheduled jobs that rely on cron in Sugar, please refer to the Schedulers documentation.
First, you must create a batch file.
- Call it
sugar.batand put it in the c:\ directory
- Assuming your php.exe binary is located at
- and your php.ini is located in
- and that you’ve installed Sugar in
- and you are running PHP 5.x
These values are most likely are different for you, so please plan accordingly. But under those assumptions, your batch file will look something like:
c:\spikesource\oss\php5\php.exe -c c:\windows\php.ini -f cron.php
Basically, this causes us to switch to the Sugar directory and, using the full path, call
php.exe with the
-f argument to run
cron.php, which is a file provided by Sugar. This file will, among other things, cause your e-mail to be checked. So now we have a batch file to run, but how do we run it? You need to create a Scheduled Task via the Windows Command Prompt. Here is the syntax used to run our batch file every 1 minute:
schtasks /create /sc minute /tn "Sugar Cron" /tr c:\sugar.bat
It’s a bit easier on Linux. First, you must edit the web server user’s “crontab” and provide information that will enable the command to run. I will assume our web server user is “apache” for this example:
crontab -e -u apache (insert the following values into the resultant editor) * * * * * cd /var/www/html/sugar && /usr/bin/php -f cron.php 2>&1
Note that it may be necessary to specify the path to the php.ini file. Some PHP distributions use separate php.ini files for Apache and command-line. Example:
* * * * * cd /var/www/html/sugar && /usr/bin/php -c /etc/php5/apache2/php.ini -f cron.php 2>&1
Apple relies on the launchd framework, which includes cron-like functionality, though it is broader in scope. It can also be used to coordinate Sugar’s scheduled jobs. It operates on XML files called “plists,” which are stored in strategic locations on the filesystem. You can create these XML/text files using your favorite editor.
Insert the following code into this file:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>com.sugarcrm.Scheduler</string> <key>ProgramArguments</key> <array> <string>/usr/bin/curl</string> <string>http://www.example.com/crm/cron.php</string> </array> <key>RunAtLoad</key> <true /> <key>StartInterval</key> <integer>1</integer> </dict> </plist>