Guide to Cron Jobs | HostGator Support
  1. Knowledge Base
  2. >
  3. Results
  4. >
  5. Guide to Cron Jobs

Guide to Cron Jobs

What is a Cron Job?

A cron is a Linux utility that schedules a command or script on your server to run automatically at a specified time and date. A cron job is the scheduled task itself. Cron jobs can be very useful for automatic repetitive tasks. Knowledge of Linux commands is required to use cron jobs effectively.

For example, you can set a cron job to temporarily delete files every week to conserve your disk space. Some programs, such as Drupal, may require you to configure a cron job to perform certain functions. 

Scripts executed as a cron job are typically used to modify files or databases. However, they can perform other tasks that don't modify data on the server, like sending out email notifications. 

In this article, we will discuss the following topics about cron jobs.

Cron job elements

Most cron jobs include three components:

  • The script that is to be called or executed.
  • The command that executes the script on a recurring basis (typically set in the cPanel).
  • The action or output of the script (which depends on what the script does).

Most scripts that require the use of a cron job will give you specific setup instructions. If you are unsure, check with the author of your script before adding a cron job.

How to create Cron on Linux or Unix

Cron daemon is a computer program or a long-running process that runs commands as a background process instead of being directly controlled by an active user. The daemon regularly checks the file: 


and the location of the files or directories: 


You need to add Crontab commands for you to make changes to the cron job. Please visit the following articles for more information about managing cron jobs.

What is a Crontab command?

The crontab command is used to edit or create a crontab file, list and remove files, and install and deinstall the cron jobs in Vixie Cron. The files in /var/spool/cron/crontabs are not to be edited directly, even though each user owns their crontab file.

You can use the crontab command for editing or setting up your own cron jobs.

  • crontab -e 
    “e” means “edit.” This is for the user to edit the crontab file of the present user. It can also be used to create one if nothing exists.
  • crontab -l 
    “l” means “list.” This lets you display the contents of a crontab file of the present user. 
  • crontab -r
    “r” means “remove.” This is for you to remove the crontab file or the entries of the present user. 

Note: This is permanent, and there may not be a prompt. Running crontab -r without a user will remove ALL the default user's crons.

  • crontab -u
    “u” means “user.” If you use this alone, it will not work. A valid username has to be written after the command and should be combined with other crontab commands.
    • To show other user’s cron jobs, combine -l with -u option.
    • To edit other user’s cron jobs, combine -e with -u option.
    • To remove other user’s cron jobs, combine -r with -u option.
  • crontab -v
    This will show the last time you made changes to the crontab file. (This command is only available on a couple of systems)

Crontab file (Time Intervals)

Cron jobs can be set to run by the minute, hour, day of the week, day of the month, month, or any combination of these.

Note: HostGator limits cron jobs on Shared servers to run in 15-minute intervals since excessive cron jobs can cause high loads on the server.

Each entry in a crontab file consists of six fields following this order:

minute(s) hour(s) day(s) month(s) weekday(s) command(s)

These fields are separated by spaces or tabs, with the first five characters as integers and the sixth as the command to execute.

minute0-59Exact minute that the command sequence executes
hour0-23Hour of the day that the command sequence executes
day1-31Day of the month that the command sequence executes
month1-12Month of the year that the command sequence executes
weekday0-6Day of the week that the command sequence executes
commandspecialComplete sequence of commands to execute

Crontab syntax and operators

In your cPanel, you may notice that the existing cron jobs look like this:

 * * * * * command(s) 
Crontab OperatorDescription
* (asterisk operator)This means any value or always. If you selected an asterisk in the Hour field, then it means the task will be performed each hour.
, (comma operator)This allows you to specify a list of values for repetition.
- (hyphen operator)This allows you to specify a range of values.
/ (slash operator)This allows you to specify values that will be repeated over a certain interval between them

Crontab variables

Here are some of the commonly used cron variables.

Cron VariableDescription
SHELLThe path of the current user’s shell, such as bash. 
PATHThe list of directories that will be in the search path for cron.
MAILThe mail storage location of the current user.
MAILTOIt sets who gets emailed with the output of each command.
HOMEThe home directory of the logged user.
EDITORThe default file editor. 
LOGNAMEThe current user's name.
TERMThe current terminal emulation.
LANGThe current locale settings
USERThe currently logged user.

One of the most common issues with cron jobs in support is that they call for the default versions of PHP on the server unless otherwise specified. For example, if the client runs a script that requires PHP 7.1 rather than run php, /home/path/to/script.php, the agent could use phpvers command in the EIG shell to match the direct path.

To schedule tasks with cron, check out this article: Setting a Cron to Run at a Specific Date and Time.

Cron permissions or access

Cron allows you to assign who can execute or not execute any file. The following files can do it:

Cron allow -  /etc/cron.allow

Cron deny -  /etc/cron.deny

Things to remember:

  • Add the name before the file, whether you want to allow or deny this specific name in using cron.
  • If you don’t want anyone to use cron, add the line ALL before the cron.deny file.
  • If both files do not exist, only the root user can use cron.
  • If both cron.allow and cron.deny have the user’s name, then the user still may use cron.
  • If cron.deny is present but is empty, all users can use cron.
  • If there’s a user in cron.deny, but there’s no cron.allow file, then ALL users can use cron, but not the ones listed in cron.deny.

Backup installed Cron job entries

To back up your cron jobs, type the following command to create a backup within the /backup/cron directory:

crontab -l > /backup/cron/root.bakup

If you wish to back up a specific user, use the following replacing userName with the user you want to generate a backup for.

crontab -u userName -l > /backup/cron/userName.bakup

Cron job limits

Shared and Reseller hosting - You may NOT run a cron job more often than every 15 minutes.

VPS and Dedicated hosting -You may run a cron job as often as desired.

CMS crons

Magento - To know more about Magento and Magento Cron, check the article Optimizing Magento.

WordPress - This is the recommended article to read for this type of CMS How To Optimize a WordPress Installation.


cURL, GET, and Wget are often used in cron jobs and are enabled on all HostGator servers by default. No further action to activate these functions is necessary. Additional information is available here.

Additional References

Here are some articles from our HostGator Support page that you may find helpful.

The following articles are for reference only, and links will open in a new tab. Please note that HostGator cannot offer direct support for the information provided below.