Job scheduling with Unix: The best alternatives to cron
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.