Cronjob Scheduling Techniques

Cronjob Scheduling Techniques With Crontab

Job Scheduler

Cron jobs are scheduled tasks that run automatically on a periodic basis on POSIX-compliant systems.

Cron jobs automate repetitive tasks such as backups, updates and system maintenance.

The command crontab is a job scheduler.

The focus of this tutorial will be on creating a custom script in PHP to demonstrate automation.

  1. Create a list of form fields.
  2. Choose command line scripting language such as Bash or PHP.
  3. Create a script to fill in form fields and submit destination.
  4. Manually run the script.
  5. Set up a cronjob to automate the script at the desired interval.

Requirements For cURL

Glossary:

POSIX

Portable Operating System Interface family of standards for maintaining compatibility between operating systems.

Job

A unit of work or unit of execution (that performs said work).

Task

A unit of execution or a unit of work.

Job Scheduler

Application for controlling unattended background program execution of jobs.

Batch Scheduling

Method of running software programs called jobs in batches automatically.

Crontab

Cron Table, configuration file that specifies shell commands to run.

Tools

Programming Tools
Name Description Example
Text editor For creating and editing source code Apache Netbeans IDE
SSH Secure Shell Client OpenSSH
Shell Access Access to the command line. Terminal
Name Description Example

Common Syntax For Crontab

Crontab
Name Description Example
Every Minute Every Weekday, Every Month, Every Day, Every Hour, Every Minute * * * * * /path-to-bash-script
Every Five Minutes Every Weekday, Every Month, Every Day, Every Hour, Every Five Minutes */5 * * * * /path-to-bash-script
Every Hour Every Weekday, Every Month, Every Day, Every Hour, Specified Minute 0 * * * * /path-to-bash-script
Every Day Every Weekday, Every Month, Every Day, Specified Hour, Specified Minute 0 0 * * * /path-to-bash-script
Every Week Specified Weekday, Every Month, Every Day, Specified Hour, Specified Minute 0 0 * * 0 /path-to-bash-script
Every Month Every Weekday, Every Month, Specified Day, Specified Hour, Specified Minute 0 0 1 * * /path-to-bash-script
Twice A Month Every Weekday, Every Month, Specified Days, Specified Hour, Specified Minute 0 0 1,15 * * /path-to-bash-script
Every Year Every Weekday, Specified Month, Specified Day, Specified Hour, Specified Minute 0 0 1 1 * /path-to-bash-script
Name Description Example

Cron Jobs

# Every Minute #
* * * * * /path-to-bash-script
# Every Five Minutes #
*/5 * * * * /path-to-bash-script
# Every Start Of The Hour #
0 * * * * /path-to-bash-script
# Every Day At Midnight #
0 0 * * * /path-to-bash-script
# Every Week On Sunday At Midnight #
0 0 * * 0 /path-to-bash-script
# Every Month On First Day At Midnight #
0 0 1 * * /path-to-bash-script
# Every Month On First Day And 15th At Midnight #
0 0 1,15 * * /path-to-bash-script
# Every Year On First Month And First Day #
0 0 1 1 * /path-to-bash-script

Explanation:

  1. Cron tables are started with the crontab command.
  2. Each cron job is of the format MIN HOUR DOM MON DOW CMD.
  3. The CMD (Command) represents the actual command or script to be run.

The code for commands is not provided in this tutorial because it is unique for specific needs. Testing cron jobs using crontab is easily performed by testing the command or script prior to creation.

Crontab Cronjobs
Crontab Displaying Multiple Cron Jobs


Usage

You can run crontab on the command-line, or integrated into an application as an extension. For this tutorial, crontab was used to create cron jobs. The command line tool was made available by installing Cronie which can be downloaded from Cronie cron daemon project. PHP scripting language can be downloaded from PHP. Then the downloaded file is extracted directly on the server or locally before individual files are uploaded if applicable.

Open Source

Cronie is licensed under the GNU General Public License Version 2.0. The copyleft license comes with strict rules and requirements to ensure the software remains free and open-source. It allows commercial use, modification, distribution, and allows making derivatives proprietary, consult the license for more specific details.

The PHP scripting language is licensed under the PHP License. The permissive license has conditions requiring preservation of copyright and license notices. Redistribution is permitted in source or binary form with or without modifications, consult the license for more specific details.

Conclusion:

Crontab is used for task scheduling and task automation using the command line tool crontab. The scheduled cron jobs can either be commands or scripts

If you enjoy this article, consider supporting me by purchasing one of my WordPress Ojambo.com Plugins or programming OjamboShop.com Online Courses or publications at Edward Ojambo Programming Books or become a donor here Ojambo.com Donate

References:

About Edward

Edward is a software engineer, web developer, and author dedicated to helping people achieve their personal and professional goals through actionable advice and real-world tools.

As the author of impactful books including Learning JavaScript, Learning Python, Learning PHP and Mastering Blender Python API, Edward writes with a focus on personal growth, entrepreneurship, and practical success strategies. His work is designed to guide, motivate, and empower.

In addition to writing, Edward offers professional "full-stack development," "database design," "1-on-1 tutoring," "consulting sessions,", tailored to help you take the next step. Whether you are launching a business, developing a brand, or leveling up your mindset, Edward will be there to support you.

Edward also offers online courses designed to deepen your learning and accelerate your progress. Explore the programming on languages like JavaScript, Python and PHP to find the perfect fit for your journey.

📖 Explore His Books – Visit the Book Shop to grab your copies today.
💼 Need Support? – Learn more about Services and the ways to benefit from his expertise.
🎓 Ready to Learn? – Check out his Online Courses to turn your ideas into results.