Webinar Lp Banner 1

Cron job scheduling simplifies workflows for teams of all sizes by eliminating manual work and ensuring tasks are completed exactly when they need to be.

Save time on routine tasks like backups, system maintenance, and monitoring with task scheduling automation tools and cron jobs.

What is a cron job?

Cron is a scheduling daemon used to execute tasks at specific times or intervals. These tasks are then called cron jobs, and are generally used to automate system maintenance or other system administrator tasks.

A cron job is a task scheduler for UNIX operating systems, like open source Linux, that allows a user to automate a task to run at a specified time. These tasks, or jobs, can be scheduled for a specific time, like day of the week, day of the month, or time of day.

Through a command line interface, system administrators use cron jobs to automate and schedule tasks like system maintenance, data backups, and monitor disk space, updating the system with security patches, checking for storage, sending email notifications, and more.

Cron jobs are written in a text editor to create a simple text file called a crontab file. This file contains the current user’s specifications for what task they want to automate and when it should be executed.

What is a crontab file?

Crontable (or cron table) is a text file that specifies the schedule of the cron jobs. There are two types of crontab files: system-wide and individual user crontab files.

User crontab files are named according to the user’s name and location, which varies by operating system, like Linux or Windows. Red Hat distributions like CentOS store crontab files in the /var/spool/cron, while crontab files are stored in the /var/spool/cron/crontabs directory on Debian and Ubuntu.

It’s possible to edit user crontab files manually, but it’s best practice to use the crontab cron command in this situation. 

System-wide crontab files can only be edited by system administrators and include the /etc/crontab file and scripts inside the /etc/cron.d directory. 

Cron Syntax

Understanding cron syntax, operators, and crontab entries can be complicated, but after getting a hang of the process, scheduling cron jobs becomes a piece of cake. Each line in a current user crontab file is made up of six fields separated by a space followed by a cron command. 

The first five fields can contain one or more possible values, which are separated by a comma, or a range of values, separated by a hyphen.

  • The asterisk (*) operator means any value or always. 
  • The comma (,) operator specifies a list of possible values for repetition. 
  • The hyphen (-) operator specifies a range of values. 
  • The slash (/) operator specifies values to be repeated with a certain interval between them. 
  • The last (L) operator is allowed for day of month and day of week fields and specifies either the last day of the month or the last X day of the month. 
  • The weekday (W) operator is allowed for the day of month field and specifies the weekday.

There are a few cron schedule macros that can be used to specific common intervals for scheduling tasks. One of these includes reboot, which enables a task to run at a scheduled time at system startup.

Crontab Variables

The cron daemon sets a few environment variables automatically, which include: 

  • The default path is set to PATH=/usr/bin:/bin.
  • The default shell is set to /bin/sh. To change the shell, use the SHELL crontab variable.

Schedule Tasks in Linux with Cron

The fastest jobs can be executed using cron is every 60 seconds, and cron jobs cannot be distributed to multiple computers on the same network.

A cron job scheduler presents numerous benefits, the most prominent being automation. Teams can use task scheduling tools to save time automating routine, manual tasks and reducing human mistakes.

Schedule tasks to run at a specific time, down to the minute, offering precision scheduling just not possible with manual efforts. For tasks that absolutely have to be executed at specific times, cron job schedulers can be trusted to get the cron job runs completed.  

Linux Crontab Command

The crontab command is among the Linux commands that allows users to install, view, and modify a crontab file in a Linux system. 

  • crontab -e: Edit or create a crontab file.  
  • crontab -l: Display the contents of a crontab file.  
  • crontab -r: Remove a crontab file.  
  • crontab -i <username>: Edit another user crontab file. This requires necessary permissions.

Redwood’s Cron Job Scheduler

Redwood has the best event-driven job scheduling software for enterprise teams looking to take advantage of cron job scheduling. Teams can easily use cron jobs to schedule end-to-end workflows and business processes with RunMyJobs by Redwood.

Use automation to schedule tasks on any platform or operating system, and use a built-in template to create processes in minutes from Redwood’s extensive template library. Schedule jobs to run in response to events in real-times, and schedule tasks across multiple timezones.

Redwood guarantees performance with predictive SLA monitoring, notifications through email or SMS, and more.  Support more than 25 scripting languages and interfaces including PowerShell and Bash, with built-in syntax highlighting.

Last but not least, Redwood University offers a number of expert tutorials for cron job scheduling and automating tasks. 

Frequently Asked Questions

How do I run a cron job every 12 hours?

To run a cron job every 12 hours, use the following cron command:

0 */12 * * *

This will run a cron job at minute 0 past every 12th hour, every day of the week, every day of the month.

Batch scheduling saves even more time than automation alone. Learn how teams use Redwood for batch task scheduling.

How do I schedule a cron job every 5 minutes?

To schedule a cron job every 5 minutes, use the following cron command:

*/5 * * * *

This will schedule a cron job to run every 5 minutes, every day of the week, every day of the month.

What are the limitations of cron?

Cron is an extremely powerful task scheduling tool, but it does present some limitations, like limited scheduling options, timezone issues, lack of built-in error handling, limited logging and output, and minimal security.

Cron jobs are scheduled using the system's timezone. If the system timezone changes due to daylight saving time or other reasons, it will affect the scheduled time of the cron job.

Minimize the security risks of cron jobs by using Redwood for security management and process automation.

What does the asterisk mean in Linux cron jobs?

In Linux cron jobs, the asterisk (*) is a character that is used to specify "any" value for a particular field.

In a cron job, there are five fields that specify the job schedule: minute, hour, day of the month, month, and day of the week. The asterisk can be used in any of these fields to indicate that the job should run every minute, hour, daily, every weekday, day of month, or day of week.

For example, the cron job entry * command means to run the command every minute of every hour, every day of the month, every month, and every day of the week.

The asterisk can also be used with a step value to run a job at specific intervals. For example, */5 * * * * command means to run the command every five minutes.

Create a bright digital future for your organization with Redwood’s process automation solutions.