Skip to content

Command line application or script which parses a cron string and expands each field to show the times at which it will run.

Notifications You must be signed in to change notification settings

akshaykhanna/Cron-Expression-Parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cron-Expression-Parser

Command line application or script which parses a cron string and expands each field to show the times at which it will run.

Setup

  • Clone repo
  • Install node (>= 14) if not already present.
  • npm install in repo folder to install node dependencies for this project.

Steps to run

Run npm run exec followed by cron_string in quotes in node terminal to print the parse cron string as output.

npm run exec '*/15 0 1,15 * 1-5 /usr/bin/find'

Run tests

npm run test

What is cron string ?

A Cron string, often referred to as a Cron expression or Cron schedule, is a string of text used to represent a schedule for executing recurring tasks or jobs on Unix-like operating systems. It specifies when and how often a task should run, down to the minute, hour, day, month, and day of the week. Cron strings are commonly used for automating routine system maintenance, running scripts, or scheduling other repetitive tasks.

It provide a flexible and powerful way to schedule recurring tasks, making them a fundamental tool for system administrators and developers working with Unix-based systems.

What is a valid cron string ?

A valid Cron string must adhere to specific rules and format to be considered valid. Here are the typical validations for a valid Cron string:

Number of Fields: A valid Cron string should consist of six fields separated by spaces: minute, hour, day of the month, month, day of the week, and the command. If there are not exactly six fields, it's invalid.

Field Ranges: Each field should contain valid values within specified ranges:

Minute (0 - 59) Hour (0 - 23) Day of the Month (1 - 31) Month (1 - 12) Day of the Week (0 - 6) Field Separators: Fields should be separated by spaces. Some Cron parsers also accept tabs or a combination of spaces and tabs.

Asterisk () Usage: An asterisk () is a wildcard character used to represent all possible values within a field. For example, * in the minute field means "every minute." However, an asterisk cannot be used in combination with other values in the same field. For instance, 1-5, * in the hour field would be invalid.

Ranges: Ranges of values can be specified using a hyphen (-). For example, 1-5 in the hour field means "from 1 to 5." Ranges should have valid start and end values.

Lists: Comma-separated lists of values are allowed within a field. For example, 1,15 in the day of the month field means "on the 1st and 15th." Lists should contain valid individual values.

Steps (/): A step value can be used to skip values within a range. For example, */15 in the minute field means "every 15 minutes." Steps should have a valid range and step value.

Command Field: The last field should contain the command or script to be executed. It may need to be a valid path to an executable script or command.

Whitespace: Leading or trailing whitespace in the Cron string should be trimmed.

Note that the specific rules and requirements for valid Cron strings may vary depending on the Cron implementation or library being used. It's essential to refer to the documentation of the Cron system or library you are working with to understand the precise validation rules it enforces.

About

Command line application or script which parses a cron string and expands each field to show the times at which it will run.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published