Scheduling cron jobs in Linux allows you to automate website administration tasks by choosing when the server does a specific action. You can configure cron jobs in Linux from the command line interface or your web hosting control panel.
Scheduling cron jobs in Linux
The Nexcess Client Portal and SiteWorx are robust tools for managing all aspects of your website hosting, including scheduled tasks. In this guide, we’ll review the process of scheduling cron jobs in Linux with a Nexcess Cloud web hosting plan via three methods:
- Your website management dashboard
- Command line interface in Linux
Overview of scheduling cron jobs in Linux
Cron is a “daemon” — a type of program that runs in the background on Unix-like operating systems and only activates in response to certain occurrences — that you can use to schedule automated tasks at specific times.
The ability to create scheduled tasks is available on all modern operating systems. The Cron program is Linux’s version of this ability. A cron job is the task itself — the action or job you program to occur at a scheduled time.
Cron jobs are especially useful for tasks you need to complete at regular intervals, such as responsibilities related to tedious administrative upkeep and system maintenance.
How to view and schedule cron jobs on the Nexcess Cloud
Nexcess provides three options for scheduling cron jobs for your websites:
- Nexcess Client Portal
- SiteWorx control panel
- Linux command line interface
The Nexcess Client Portal and SiteWorx make scheduling cron jobs in Linux much easier and faster by providing a graphical user interface. All you need to do is specify when you would like a scheduled task to run, and a cron job will generate and show up on the crontab automatically.
The Scheduled tasks interface in the Nexcess Client Portal is the best option for beginners. More experienced users can schedule cron jobs from the Linux command line interface or use the crontab generator with advanced features provided by SiteWorx.
Below, we will review how to view your cron jobs and schedule new tasks using all three options.
Scheduling cron jobs in Linux from the command line
Scheduling cron jobs in Linux from the command line requires Secure Shell (SSH) access to your website and the ability to specify the time intervals manually by configuring each of the five fields. Alternatively, you can use a third-party crontab generator to configure the cron job automatically.
The crontab command can help you view the existing cron jobs and add new scheduled tasks.
You specify what you would like to do by using a specific flag. The -l flag, which is short for list, allows you to view all scheduled jobs. The -e flag allows you to edit the list so that you can add or remove cron jobs:
View All Existing Cron Jobs [wordpress@host wordpress]# crontab -l MAILTO="firstname.lastname@example.org" 5 */2 */5 * * /var/www/wordpresstest.com/html/website_manual_backup.sh >/dev/null 2>&1 */30 * * * * /bin/php /var/www/wordpresstest.com/html/custom_script.php >/dev/null 2>&1
The crontab -e command will open your website’s crontab in one of the text editors. You can modify it just like any text file. Save the file to apply all changes. Then, verify the crontab has been updated by using the crontab -l command.
Scheduling cron jobs in Linux from the Nexcess Client Portal
The Nexcess Client Portal offers advanced options for website management. It presents user-friendly administrative capabilities through one comprehensive, centralized, and streamlined system. With the Nexcess Client Portal, you can manage your cloud hosting services, optimize individual websites, and perform a variety of other tasks with ease.
You can manage cron jobs for your website from the Scheduled Tasks menu of your Site Dashboard. Log in to your website’s management dashboard and choose the corresponding option.
The General Options section contains the list of paths to check for binaries. It allows you to configure an address to receive emails notifying you of any issues with existing cron jobs.
Click the Update button to add or change the existing email address. Save the changes in the popup window that will appear:
You can see the list of your cron jobs under Tasks. You can remove or temporarily disable the existing scheduled tasks or add a new one by clicking the Add Task button on the right side of the page. Insert the script and choose when it needs to be executed.
The Nexcess Client Portal allows you to configure scheduled tasks to run monthly, daily, or hourly. Alternatively, you can set the time interval to 5, 15, or 30 minutes. These options should cover most use cases. Adding a more complex cron job is possible from SiteWorx or the Linux command line interface.
After you have specified the script and chosen the frequency, click the Add button, and a new cron job will appear under Tasks:
Scheduling cron jobs from the SiteWorx control panel
The SiteWorx control panel includes more advanced options for scheduling cron jobs. Navigate to the Control Panel menu from your dashboard and launch SiteWorx by selecting the Launch Control Panel button.
Expand the list of options under Hosting Features from the left menu and choose Cron jobs. The management interface is similar to the one in your Nexcess Client Portal. You can add and remove tasks or edit the existing tasks. These cron options include temporarily disabling tasks.
The Cron Options section allows you to modify the general cron settings, including the email address to be notified of the output of each cron job, the shell used, and the path variable. Most of the time, you don't need to change anything except the email address:
SiteWorx provides two crontab generation interfaces: Simple and Advanced. The Advanced interface provided by SiteWorx lets you to set up the scheduled tasks manually. The Simple interface is essentially a crontab generator that provides many options for scheduling cron jobs:
Frequently asked questions about cron jobs in Linux
Below, we have answered website owners' most common questions about scheduling cron jobs in Linux.
What is a cron job?
Cron jobs are the scheduled tasks controlled by cron and executed at a specific time that you can configure for the whole system or a particular user or website.
What is used as a task scheduler in Linux?
Cron, also known as cron daemon, is an analog of the task scheduler for Linux systems. Cron provides the ability to schedule recurring tasks at chosen time intervals.
What is the difference between system and user cron jobs in Linux?
Cron jobs are widely used for performing both server and individual website administration tasks. The main difference between system- and user-scheduled tasks is their scope. System cron jobs affect the whole server, while user tasks can only work in the area available to the specific user defined by their permissions.
System cron jobs are often used for server maintenance, including installing updates, running backups, and log rotation. Most system administrators configure additional cron jobs that automate tasks specific to the server environment.
User cron jobs are usually aimed at performing different website administration tasks, including managing email and backups. For example, many security and backup plugins for WordPress use cron jobs to run backups and launch scheduled malware and vulnerability scans.
What structure do cron jobs use?
All cron jobs in Linux have the same structure that defines when the scheduled tasks need to run and what program or script is to be executed — and how. Knowing how to view cron jobs and modify them can help you customize the way specific tasks are performed on your website.
The standard structure of a cron job looks like this:
[Minute 0-59] [Hour 0-23] [Day of Month 1-31] [Month 1-12] [Day of week 0-7] [command or a program to execute] .---------------- minute (0 - 59) | .------------- hour (0 - 23) | | .---------- day of month (1 - 31) | | | .------- month (1 - 12) OR jan,feb,mar,apr ... | | | | .---- day of week (0 - 6) (Sunday= 0 or 7) OR sun,mon,tue,wed,thu,fri,sat | | | | | * * * * * command to be executed
As you can see, you need to specify when exactly you would like your scheduled task to run. Each field representing the time or date has a numeric value.
- Minute: A number between 0 and 59.
- Hour: A number between 0 and 23, as cron uses the 24-hour format.
- Day of Month: A number between 1 and 31.
- Month: A number between 1 and 12.
- Day of the Week: A number between 0 and 7, with Sunday being represented as either 0 or 7.
Cron allows you to use special characters and time definitions to set up cron jobs that run at the chosen time. For example, you can configure cron jobs for the last day of the month or that run every few days.
Where are scheduled tasks stored, and how do I view cron jobs in Linux?
Most cron jobs are stored in files named crontabs. Each user has a separate crontab that represents a list of cron jobs configured for it. You can view crontabs from the Linux command line interface, SiteWorx, or your hosting control panel. Hosting control panels retrieve the list of cron jobs from the server and present it to you for easier navigation.
Are there any tools for generating cron jobs?
Configuring cron jobs manually from the Linux command line interface is challenging, so various tools exist for scheduling cron jobs in Linux. You can use third-party crontab generators or configure cron jobs from the graphical interface provided by the hosting control panel.
Schedule cron jobs in Linux with help from Nexcess
Scheduling cron jobs in Linux is a great way to automate your website administration tasks. If you’re just getting started with scheduled tasks in Linux, we strongly recommend using the Nexcess Client Portal or SiteWorx instead of the Linux command line.
See all our hosting products at Nexcess
Whether you're creating a brand new site or looking for better hosting, we can help you find the right product or customized plan to help you get there.
The user-friendly Nexcess Client Portal allows you to manage all technical aspects of web hosting. And our 24/7/365 support team can help you resolve any issues that arise.
A Nexcess-managed hosting plan will help you build better, regardless of the industry. We optimize our services for Linux, ensuring top-notch performance and security specifications. Check out our plans and learn how we can help your website today.
Note about the original publication date
This article was originally published in September 2019. It has since been updated for accuracy and comprehensiveness.