We’ll show you, how to use CentOS crontab. How to automate system tasks on CentOS 7, using CentOS crontab. The crontab software utility is a time-based job scheduler in Unix-like operating systems. Cron is driven by a crontab (cron table) file, a configuration file that specifies shell commands to run periodically on a given schedule. The crontab files are stored where the lists of jobs and other instructions to the cron daemon are kept. Users can have their own individual crontab files and often there is a system-wide crontab file (usually in /etc or a subdirectory of /etc) that only system administrators can edit.
Table of Contents
1. Connect via SSH and update the system software
First of all, connect to your Linux VPS via SSH and update all your system software to the latest version available. You can use the following command to do that:
2. Verify if cronie package is installed
To automate the system tasks, or better known as jobs under Linux, you can use a utility called Cron. Using Cron you can run scripts automatically within a specified period of time, create a backup of your databases or other important files, monitor the services running on your server, and many other things. To use the Cron utility, you need to install the cronie
package on your system. It should be already installed on your server. To confirm, issue the following command:
3. Install cronie package
If it is not installed, you can use yum to install it. Yum is a package manager which you can use to install and manage software on CentOS 7. Run the command below:
4. Check if crond service is running
The cron jobs are picked by the crond service. To check whether the crond service is running on your CentOS VPS, you can use the following command:
5. Configure cron jobs
To configure cron jobs you need to modify the /etc/crontab
file. Please note that it can only be modified by the root user. To check the current configuration, you can use the following command:
The output should be similar to the one below:
As you can see the crontab file already contain an explanation about how to define your own jobs. The syntax is the following:
An asterisk (*) in the crontab can be used to specify all valid values, so if you like the command to be executed every day at midnight, you can add the following cron job:
Your cron job will be run at:
Specific users can create cron jobs too. The cron jobs for specific users are located in /var/spool/cron/username
. When you create cron jobs for specific users you do not need to specify the username in the cron job. Therefore the syntax will be like the one below:
6. Restart the crond service
After you make the changes restart the crond service using the command below:
For more information you can check the man pages:
and
If it is difficult for you to set up correct cron jobs at the beginning, you can use a cron job calculator to generate the cron job expression. There are several good cron job calculators available on the Internet.
Read Also: Ubuntu crontab
Of course, you don’t have to use CentOs crontab, if you use one of our CentOS VPS hosting services, in which case you can simply ask our expert Linux admins to help you with crontab on CentOS to Automate system tasks. They are available 24×7 and will take care of your request immediately.
PS. If you liked this post, on how to use the CentOS crontab, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.