Using cron to schedule tasks

To help your website to run more efficiently, you should conduct regular website maintenance. You can automate maintenance tasks or jobs to run at scheduled intervals using the Cron page at Cloud > Cron.

Scheduled jobs are specific to the Acquia Cloud environment that they are created in. While you cannot create a job that executes a command across multiple environments based on the same schedule, you can create a job for each environment, with each of these jobs using the same command line and schedule.

You should use the Cloud > Cron page for scheduled jobs, rather than the default Drupal cron or any of the contributed cron modules, such as Elysia Cron or Ultimate Cron. Compared to other cron solutions, using the Cloud > Cron page is more reliable and provides extensive and integrated logging for Acquia Cloud websites.

In Drupal 7, the default cron (poor man's cron) is enabled by default and you should disable it. To do this, go to http://[site_URL]/admin/config/system/cron, and in the Run cron every list, click Never. The default Drupal cron is triggered by website activity, so relying on Acquia Cloud instead ensures that cron jobs are run on the schedule you specify, and not just when the website is visited. This both improves reliability and avoids the performance reduction on page requests.

If you do not have an Acquia Cloud subscription, but have an Acquia Basic subscription (which means your website is not hosted by Acquia Cloud), you can configure how often cron runs from the Subscription > Site Grouping page. For more information, read Configuring cron for Basic subscriptions.

Creating scheduled jobs

To create a new cron job for an environment:

  1. Sign in to Acquia and open the Cloud > Cron page for your website.

    Cron page

  2. Click Add cron job for an environment.
  3. In the Add cron job to [env] dialog, enter a descriptive name for the job in the Name field.

    Add a cron job

  4. In the Cron command field, enter the command that you want to have Acquia Cloud regularly run for the environment. You can enter any commands that are allowed from an SSH connection to the website environment. A command cannot be longer than 255 characters. If you need to execute a command longer than that, you should incorporate it into a shell script that you run under cron.

    Remember that % is a special character in cron commands and if your command uses it, you have to escape it with a backslash. For some common cron examples that you can use in this field, see the Using cron command examples section on this page.

    You should test commands using SSH on your Acquia Cloud environment to make sure they work before adding them as automated cron commands.

  5. Select how often you want to run the command from the menus in the Command frequency section:
    • Every minute
    • Every hour, at a number of minutes past the hour
    • Every day, at a certain time
    • Every week, at a certain day of the week and time of day
    • Every month, at a certain day of the month and time of day
    • Every year, at a certain month, day of the month, and time of day

    As an alternative, you can enter the cron frequency as a string. For more information, see Cron time string format.

  6. Click Add.

After you create a new job, Acquia Cloud displays the job in the list of cron jobs for the environment in which it was created.

Important: Redirect cron output

When cron runs, and the output is not redirected to stdout, the cron user sends an email to the website user on the same server. This email is saved in /var/mail. If the messages are never picked up or cleared, this eventually fills the disk, which can cause serious problems, including possibly bringing your website down. Therefore, cron jobs should always include a logging statement. For example:

drush @[site].[env] -dv -l http://[site_URL] cron
&>> /var/log/sites/${AH_SITE_NAME}/logs/$(hostname -s)/drush-cron.log

In this example, &>> /var/log/sites/${AH_SITE_NAME}/logs/$(hostname -s)/drush-cron.log logs the cron output to a drush-cron.log file in the server's logs directory, where it will be rotated along with the other website logs in that directory. The log file will be rotated only if it is named drush-cron.log. For more information, see About Acquia Cloud logging.

Managing scheduled jobs

Each job that you create on the Cron page has links to help you manage the job, which allow you to do the following:

  • Suspend - Stops the scheduled job from running until you click Resume.
  • Edit - Opens a window that allows you to change the attributes of the scheduled job. After you make your changes, click Update.
  • Remove - Opens a window that deletes the scheduled job when you click Remove. If you remove a scheduled job, you cannot recover it, and you must manually re-create it to restore the job.

Cron and memory limits

Two approaches in using drush cron are to use the Acquia Cloud wrapper script for drush cron or to execute drush cron directly. These approaches have different memory limits. When you use the Acquia cron wrapper, the cron job uses the PHP memory limit for your environment (by default, 128 MB). When you use cron directly, it uses the command line process memory limit, which is 512 MB. If you find that your cron jobs fail to complete, try defining them to use drush cron directly to take advantage of this higher memory limit. For related information, see Debugging cron.

Cron command examples

Use the following examples as you create scheduled jobs for your website's environments.

Using drush cron

To use drush cron for enhanced cron performance, select from the following methods:

In each of these examples:

  • [sitename] is the name of your website on Acquia Cloud.

    To find your [sitename], sign in to Acquia and go to Cloud > Workflow. The sitename is the string in the site URL after the protocol (http://) and before the specific domain designators (usually or

    Finding your sitename in the site URL

  • [site] is the name of your website on Acquia Cloud (as listed on the Cloud > Users and keys page).

    To find your [site] name, sign in to Acquia and go to Cloud > Users and keys. The site name is the value before the ampersand ( @ ) in the SSH command line.

  • [env] is your environment (usually one of dev, test, or prod).
  • [site_URL] is your website's URL (as listed on the Cloud > Domains page). If you are using Drupal multisite, your cron jobs are specific to each website in the multisite installation. Use the URL of the website in the installation that you wish to target.

Use the Acquia Cloud wrapper script for drush cron

Use a cron command like this:

/usr/local/bin/ [sitename] http://[site_URL]

Note that you do not need to append a cron_key to the website URL. The output of drush cron is logged to a file with a name like /var/log/sites/[site].[env]/logs/[server]/drush-cron.log. For example, if your site name was example, the log file for the prod environment might be named /var/log/sites/

Execute drush cron directly

drush @[site].[env] -dv -l http://[site_URL] cron &>> /var/log/sites/${AH_SITE_NAME}/logs/$(hostname -s)/drush-cron.log

In this example, &>> /var/log/sites/${AH_SITE_NAME}/logs/$(hostname -s)/drush-cron.log logs the cron output to a drush-cron.log file in the server's logs directory. As already noted, cron jobs should always include a logging statement, as in this example.

Executing a shell script

You can create cron jobs to execute shell scripts that you have written.

For this example we will assume that you have added scripts/ to your repository.


where [site].[env] is your site name and environment.

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
By submitting this form, you accept the Mollom privacy policy.

Contact supportStill need assistance? Contact Acquia Support