Cron Jobs
outline
Cron jobs are scheduled tasks that the system runs at predefined times or intervals. Typically, a cron job involves a series of simple tasks that the system runs from a script file.
Important :
- Be careful when scheduling cron jobs. We recommend that you allow sufficient time between cron jobs to allow the previous cron job to complete. If you schedule it to run too frequently, the server may start another cron job before the last cron job finishes. This duplication can hinder performance.
- For more information about cron tasks, see Cron in Red Hat read the Scheduling a Cron Job document.
Add cron email
The Cron Email section of the interface allows you to enter an email address where you want the system to send notifications when a cron job is performed. To set up your email address, follow these steps:
1. Enter the email address to receive notifications in the Email text box.
2. Click Update Email.
Email Notifications Disable
Remove the email address to disable email notifications for all cron jobs.
To disable email notifications for a single cron job, follow these steps:
1. In the Current Cron Jobs table, find the cron job for which you want to disable email notifications and click Edit.
2. In the Command text box, add the line /dev/null 2 > &1 to the end of the command. For example: /usr/local/cpanel/bin/is_script_stuck /dev/null 2 > &1
3. Save your changes.
Add cron job
To create a cron job, follow these steps:
1. Select the interval at which you want the cron job to run from the appropriate menu or enter a value in the text box.
- Common Settings—Select a commonly used interval. The system configures the appropriate settings in the Minute, Hour, Day, Month, and Weekday text boxes.
- Minute—The number of minutes each hour that the cron job will run, or the number of minutes between each hour that the cron job will run.
- Hour—The hour of each day at which the cron job will run, or the number of hours between each hour the cron job runs.
- Day—The day of the month on which the cron job will run, or the number of days between each hour the cron job runs.
- Month—The month in the year in which the cron job will run, or the number of months between each time the cron job runs.
- Weekday—The weekday on which the cron job will run.
- In the Command text box, enter the command to be executed by the system.
2. Select the interval at which you want the cron job to run from the appropriate menu or enter a value in the text box.
Important :
- minutes , hours , days , Month , Weekday ( Minute , Hour , Day , You must specify settings for the Month , Weekday) and Command (Command) text boxes.
- Be very careful when using the rm command for cron tasks. If you don't declare the correct options, it may delete data in your home directory.
- When a cron job runs a custom script, the script needs execute permission. For more information, read Red Hat's Linux Permissions document.
Note : Specify the absolute path to the command to run.
For example, to run the public_html/index.php file in your home directory, type the following command:
/home/user/public_html/index.php
3. Click Add New Cron Job.
cron task example
To run a script residing in your home directory once an hour, follow these steps:
1. In the Common Settings menu, select the Once Per Hour (0 * * * *) option.
2. In the Command text box, enter the name of the script. For example, ./my-script.sh
Do forget
You must set the correct file permissions to allow script execution.
3. Click Add New Cron Job. The interface displays a success message.
View existing cron jobs
Current Cron Jobs table displays existing cron jobs.
Cron Tasks Editing
To edit a cron job, follow these steps:
1. Find the cron job you want to edit and click Edit (Edit) .
2. Edit the settings you want to change and click Edit Line .
Cron Task Delete
To delete a cron job, follow these steps:
1. Click Delete ( Delete next to the cron job you want to delete).
2. Click Delete .
View original text: Cron Jobs