Rmj

Job scheduling is a critical aspect of proficient Unix administration, giving users the ability to automate tasks and streamline workflows. While the crontab utility and cron job scheduler are powerful tools for job scheduling with Unix, third-party tools and alternative methods — open-source and closed-source options — can offer more advanced features for enterprise teams.

Here, we’ll take a look at:

  • Common Unix job scheduling commands
  • Using the crontab utility for job scheduling with Unix
    • Crontab in Linux
    • Crontab entries
    • Permissions and log files
    • Syntax and possible values
  • Scheduling batch jobs on Unix
  • How to schedule tasks with RunMyJobs by Redwood
  • Job scheduling with Unix FAQs 

Common Unix job scheduling commands

Unix offers various commands and utilities for job scheduling, including the crontab utility and the cron job scheduler. The crontab utility allows users to create, edit and manage the cron table, which contains a list of jobs and their schedules. On the other hand, the cron job scheduler is responsible for executing these jobs based on specified schedules. These commands also allow for integration with other workload automation tools and task schedulers for more complex job orchestration.

Some common Unix job scheduling commands include: 

  • crontab : Create, edit and manage cron jobs. 
  • at : Schedule one-time jobs. 
  • batch : Schedule jobs intended for execution when system load is low. 
  • crontab -l : List current scheduled cron jobs. 
  • crontab -e : Edit the crontab file. 
  • crontab -r : Remove scheduled jobs. 

Using the crontab utility for job scheduling with Unix

Crontab in Linux

Crontab is a command-line utility widely used for job scheduling in Linux distributions. It provides a straightforward and flexible way to schedule tasks at specific times or intervals. Each user on a Linux system can have their own crontab file, so individual users can schedule their own jobs, which can integrate with API calls for triggering workflows or notifications when certain tasks complete.

To access the crontab, use the following command: 

crontab -e

This crontab command will open the file in a text editor, allowing the current user to view and modify scheduled jobs. Each line in the crontab file represents a job and its schedule.

Crontab files are located in the cron.d directories and can be edited using Linux commands. Specific files like cron.allow and cron.deny control which cron jobs access permissions. 

Crontab entries

Crontab entries consist of six fields separated by spaces or tabs. The fields represent the minute, hour, day of the month, month, day of the week and command to be executed.

30 9 * * * /usr/bin/command-to-be-executed

The above example is initiating the command: /usr/bin/command-to-be-executed to run every day at 9:30 AM.  

Permissions and log files

When using the crontab utility, it’s important to consider the permissions and log files associated with scheduled jobs. Ensure the user account executing the crontab has appropriate permissions to perform the scheduled tasks. It’s also good practice to redirect cron job output to a log file for future reference and troubleshooting.

Syntax and possible values

The syntax of crontab entries allows for a good deal of flexibility when scheduling jobs. For each field, specific values or special characters are used to define the schedule. For example, an asterisk (*) indicates all possible values for a field.

Below are a few common examples of crontab entries: 

0 3 * * * /path/to/backup-script.sh

The above entry schedules a backup script to run at 3:00 AM every day.

0 0 * * 1 /path/to/weekly-task.sh

The above entry schedules a weekly task to run at midnight every Monday. 

Scheduling batch jobs on Unix with cron jobs

Cron jobs are managed by the cron daemon, which periodically checks the cron table and executes scheduled jobs according to scheduled times.

To schedule a batch job using cron, add a new line to the cron table with the desired schedule and command: 

0 2 * * * /usr/bin/batch-command

In the above example, /usr/bin/batch-command will run daily at 2:00 AM. 

Save the job and exit the user crontab file, and the cron daemon will automatically pick up the changes and begin executing the scheduled jobs. This capability is essential for real-time job orchestration, including complex processes integrated with SQL databases and various apps via REST API to enable file transfer and more.

Schedule tasks with RunMyJobs by Redwood

In addition to the built-in job scheduling tools in Unix, there are also third-party tools available for workload automation (WLA)and task scheduling. RunMyJobs by Redwood is a comprehensive platform for scheduling and managing jobs across various operating systems, including Unix and Linux systems.

Redwood’s job scheduling software offers a user-friendly user interface to simplify the process of scheduling and monitoring tasks. It allows admins to define complex dependencies, set up alerts and manage job execution across distributed systems, thus increasing the scalability of scheduled jobs. Low-code development supports more than 25 scripting languages and shell scripts, including Python, PowerShell, SQL, Bash (Ubuntu) and more, with built-in syntax highlighting and parameter replacement. Teams can access countless tutorials and other resources through Redwood University, which offers online training to match specific roles and levels of experience.

Linux open-source FAQs

How do you schedule jobs in Linux?

There are various methods for scheduling jobs in Linux. Here is one tutorial using the crontab utility:

  1. Open the terminal on the Linux system.
  2. Launch a text editor with admin privileges using the sudo command. For example, for Debian distribution, the command would look like this using Bash:
    sudo nano /etc/crontab
  3. The above command will open the system-wide crontab file for editing. Users may need to enter their password again to regain admin privileges.
  4. In the crontab file, create a new line at the bottom of the file to schedule a new job.
  5. Crontab entries consist of six fields: minute, hour, day of the month, month, day of the week and the command to be executed. Syntax follows this pattern:
    * * * * * command-to-be-executed
  6. The asterisk is used to indicate a specific value for each field. Replace “command-to-be-executed” above with the command to schedule.

You may also use job scheduling tools like Dkron, Schedulix or ActiveBatch by Redwood to save time with tasks for a variety of use cases across the enterprise.

See how teams optimize workflows with RunMyJobs’ batch scheduling capabilities.

How do I schedule a Unix job without cron?

An alternative approach to scheduling jobs without cron is the at command. This schedules a one-time job instead of a recurring job.

Simply use the at command followed by the desired time for the job. After the command is executed, the terminal will switch to a new prompt. Here, the command can be entered to execute at a specific time. The atq command can be used to view a list of scheduled jobs.

For real-time orchestration, consider open-source job schedulers that support Docker and plugins for extended functionality.

Another alternative approach to cron job scheduling is RunMyJobs by Redwood for workload automation.

Can you schedule jobs in Linux with RunMyJobs?

Yes, you can schedule jobs on Linux distributions and Unix operating systems using the featherweight platform agent in RunMyJobs by Redwood. Most of the time, an agent is not required, but when connecting to operating systems like Linux, the agent gives users access to the Linux tools they need. You can use the Unix platform agent on any supported operating system where the native API is Unix, including Linux distributions and macOS.

1 GARTNER is a trademark of Gartner, Inc. and/or its affiliates. 2 Magic Quadrant is a trademark of Gartner, Inc. and/or its affiliates.