(9 MIN READ)

Transform Productivity with Linux Job Scheduling

Learn more about Linux job scheduling and optimize your workload automation.

Written by Editorial Staff. Last Updated:

Linux is a free, open source operating system known and loved by technical teams across the globe. This OS is extremely popular with developers of all experience levels and startup teams because it can be customized more than other operating systems and offers flexible setup depending on a team’s environment variables.

Something teams of all sizes use Linux for is scheduling jobs and automating tasks. The most popular method for scheduling jobs in Linux is cron jobs.

What is cron?

Cron is a system process that automatically performs tasks based on a specific schedule. Getting its name from the Greek word “Chronos,” meaning time, cron refers to a set of commands used to run regular scheduled tasks.

Cron is a job scheduling utility that exists in Unix-like systems. The cron deamon runs in the background to enable cron job scheduling functionality. There is a cron file for each user in the /etc/cron.d/ home directory, while the /etc/crontab file is system-wide. Every user manages their own scheduled jobs and cron configuration file, which could look something like this:

$ sudo systemctl status crond
● crond.service - Command Scheduler
Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2022-11-11 15:13:12 -03; 1h 17min ago

The above example is referenced from a Red Hat system administrator article.

What is crontab?

Cron reads the crontab to run predefined scripts. Crontab means “cron table” and uses the cron job scheduler to execute tasks. Crontab is also the name of the program that is used to edit the schedule of tasks. This program is driven by a crontab file, or configuration files, that directs shell commands to run on a specific time schedule.

Using specific syntax allows users to configure a cron job to schedule scripts or other commands to run automatically. When writing out a crontab command for execution, use an asterisk to match any value, use hyphens to define a range (1-10; 50-100; etc), and use commas to separate defined ranges like apr-june, oct-dec.

What are cron jobs?

Any action that you schedule through cron is called a cron job. Cron jobs automate routine tasks to run at a scheduled time, and can be set to run by day of the week, day of the month, month of the year, weekday, etc.

Linux Job Scheduling with Cron

Using cronjobs in Linux has numerous benefits. This method enables teams to use the Linux operating system to schedule a backup of log files, delete old log files, archive and purge database tables, send email notifications, clear cached data, and automate Unix jobs and system maintenance.

The Linux system pack already has a task scheduler named crontab which can be scheduled to run an automated process with root user permissions, making changes for a system administrator easier.

Cron Job Syntax for Linux Task Scheduling

To modify scheduled cron jobs, edit the crontab file or create files inside the crond home directory using necessary parameters.

Crontabs use the following parameters for adding and listing cron jobs using the command line:

  • crontab -e: Edits crontab entries to add, delete, or modify cron jobs.
  • crontab -l: List all cron jobs for the current user.
  • crontab -u username -l: List another user’s crontab.
  • crontab -u username -e: Edit another user’s crons.

When listing crons, users will see a series of asterisks, like this example below:

* * * * * sh /path/to/script.sh

Each asterisk represents minutes, hours, days, months, or weekdays.

sh indicates the shell cript is a bath script, and /path/to/script.sh specifies the path to script.

Examples of Using Crontab to Schedule Tasks in Linux

Some examples of scheduling cron jobs in Linux include:

0 8 * 8 * will schedule a task for 00:08 in August.

8 5 * * 6 will schedule a task for 05:08 on Sunday.

0 12 * * 1-5 will schedule a task every day of the week at 12:00.

Linux Job Scheduling with ActiveBatch

ActiveBatch is a workload automation and job scheduling tool that helps teams automate cross-platform IT and business processes. The Linux job scheduler features day and time scheduling options for scheduling tasks at specific times, including day of the week and day of the month.

An integrated cron jobs library sets ActiveBatch’s Linux job scheduling solution apart, providing hundreds of pre-built job actions. Teams can use ActiveBatch to easily schedule tasks and cron jobs without needing a tutorial or managing complex configurations.
With numerous extensions for popular web apps, teams can build and automate complex task scheduling workflows from a central system. ActiveBatch also makes it easy to connect to applications with API endpoints and perform command line functions.

ActiveBatch’s Linux job scheduler enables teams to schedule tasks on the operating system of their choice including Windows, Linux, UNIX, and IBM iSeries AS/400, and integrate with other job schedulers, including cron jobs for added convenience.

Cron job automation provides functionality like delivering notifications, writing to the event log file, and more. Teams can use default load balancing functionality to reduce wait times, and manage the provisioning of infrastructure resources.


Frequently Asked Questions

How do I schedule my daily job in Linux?

Cron is a time-based job scheduler in Unix-like operating systems, which allows you to run Linux commands or scripts at a specific time or interval. To schedule a daily job in Linux using cron, take the following steps:

1. Type the following command into your terminal to open the crontab configuration file: crontab -e. This will open your default text editor and deploy the crontab file. 
2. In your text editor, add a new line for your daily job with the following syntax:
* * * * * /path/to/command. This syntax represents the following time parameters in order: minute, hour, day of the month, month, and day of the week. The asterisk (*) character means “any” value, so this example will run the command every minute of every hour, every day of the month, every month, and every day of the week.
3. Replace path/to/command with the command or script you want to run.
4. Save and close the crontab with a Ctrl + X to confirm the changes.

Learn more about using cron job software for workflow automation using ActiveBatch.

How do I install cron?

While cron is typically already installed by default on most Linux machines, users can install cron through the following steps:

1. Open your preferred terminal window. 
2. Update your package listing using the following command: sudo apt-get update This command is for Ubuntu or Debian based distributions. If you’re using a different distribution, you may need to use a different command or package manager.
3. Install cron using the following command: sudo apt-get install cron This command will install the cron package and any dependencies.
4. Once installation is complete, you can verify cron has been installed by running the following command: sudo systemctl status cron

ActiveBatch’s workload automation tool offers dozens of tools to maintain and integrates shell scripts of any language.

What is * in a cron job?

* is a cron expression that defines a specific time for running a cron job. In a cron expression, there are five fields separated by spaces, each representing a unit of time. The five fields represent, in order:

1. Minute (0-59)
2. Hour (0-23) 
3. Day of the month (1-31) 
4. Month of the year (1-12 or Jan-Dec)
5. Day of the week (0-7 or Sun-Sat)

The*” character in each field means “any value“, so the expression: “* * * * *” means “run the cron job every minute, every hour, every day of the month, every month of the year, and every day of the week”.

Replace any or all of the asterisk characters with specific values to define a more precise schedule. For example, “0 4 * * *” means “run the cron job at 4:00 AM every day“, while “0 0 1 * *” means “run the cron job at midnight on the first day of every month.

Automate and orchestrate diverse system processes using ActiveBatch’s cross-platform job scheduling software.

Does Linux have a scheduler?

Linux has a built-in scheduler called the Completely Fair Scheduler (CFS), which is responsible for managing and distributing CPU time among processes. The CFS is a process scheduler that provides fairness, low latency, and scalability to the Linux kernel.

See how batch task scheduling with ActiveBatch can help you manage critical business and IT jobs.

What Linux tool can be used to schedule an execution of?

There are a number of Linux tools that can be used to schedule tasks. These include: 

● Cron: Cron is a time-based scheduler in Linux that allows users to schedule tasks (commands or scripts) to run at specific intervals. Cron can be used to schedule tasks for day of week, weekly, day of month, month of year, or annual execution.
● At: At can be used to schedule one-time jobs to run at a specific time in Linux. Unlike Cron, At is designed to run a job only once on a specific time and date.
systemd timers: Systemd is a system and service manager for the Linux operating system. Systemd timers provide a way to schedule tasks to run at a specific time, after a certain delay, or on a recurring schedule.
● Anacron: Anacron is used to run jobs that should be executed regularly, but not necessarily at a specific time. Anacron is designed to handle jobs that may not run due to system downtime or other issues requiring a reboot.

The at command is considered one of the most useful for scheduling one-time jobs in Linux. The at package installs other binaries that are used in tandem with the main command. The package provides the atd daemon which is what users will interact with using the at and atq commands.

Compare Linux job scheduling with Windows job scheduling using ActiveBatch solutions.