Advanced
Cron Jobs
Updated: 26 February 2024What is a Cron Job?
A cron job is a scheduled task that automatically executes scripts at specific intervals on your server. These tasks can include backing up databases, sending emails, cleaning up files, and much more.
Accessing Cron Jobs in cPanel
- Log into your cPanel account.
- Under the Advanced section, click on Cron Jobs.
Creating a Cron Job
Once you've accessed the Cron Jobs page, follow these steps to create a new job:
- Under the Add New Cron Job section, select the desired time interval for your cron job. You can choose from several presets, such as Once Per Minute, Once Per Hour, etc. Alternatively, you can manually set the frequency of execution in the Common Settings dropdown menu.
- In the Command field, enter the command or path to the script you want the cron job to run. For example, to run a PHP script, your command might look something like this:
/usr/bin/php /home/username/public_html/script.php
- Click the Add New Cron Job button to save your settings.
The new cron job will now automatically run at your specified intervals.
Managing Cron Jobs
Under the Current Cron Jobs section, you'll find a list of all your existing cron jobs. Here, you can Edit or Delete each job as needed.
Email Notifications
cPanel can send you an email every time a cron job runs. To enable this:
- Under the Email section, enter your email address in the Email field.
- Click the Update Email button.
Tips and Warnings
Use Cron Wisely
Cron jobs can be resource-intensive, so it's important to use them sparingly. If you set up too many cron jobs or set them to run too frequently, you could slow down your server or exceed your hosting account's resource limits.
Be careful with commands
When setting up a cron job, be extremely careful with your commands. A single mistake could cause serious problems. Always double-check your commands and test them manually before setting up a cron job.