A command-line tool that validates cron expressions using the Quartz Scheduler's CronExpression.isValidExpression() method.
- Validates cron expressions using the industry-standard Quartz library
- Returns proper exit codes (0 for valid, 1 for invalid)
- Supports both command-line arguments and stdin input
- Perfect for use in shell scripts and CI/CD pipelines
- Pipe-friendly for Linux/Unix environments
- Provides
CronValidator.isValidExpression()static method for programmatic use
mvn clean packageThis will create cronvalidator.jar in the target/ directory.
java -jar target/cronvalidator.jar "0 0 12 * * ?"
echo $? # Returns 0 for valid, 1 for invalidecho "0 0 12 * * ?" | java -jar target/cronvalidator.jar
echo $? # Returns 0 for valid, 1 for invalid#!/bin/bash
CRON_EXPR="0 0 12 * * ?"
if java -jar cronvalidator.jar "$CRON_EXPR"; then
echo "Cron expression is valid"
else
echo "Cron expression is invalid"
fi# Validate multiple cron expressions
cat cron_expressions.txt | while read line; do
if echo "$line" | java -jar cronvalidator.jar; then
echo "$line - VALID"
else
echo "$line - INVALID"
fi
doneYou can also use the CronValidator.isValidExpression() method directly in your Java code:
import io.github.grokify.cronvalidator.CronValidator;
public class Example {
public static void main(String[] args) {
String cronExpr = "0 0 12 * * ?";
boolean isValid = CronValidator.isValidExpression(cronExpr);
System.out.println("Expression '" + cronExpr + "' is " + (isValid ? "valid" : "invalid"));
}
}0- Cron expression is valid1- Cron expression is invalid or error occurred
This tool uses Quartz cron expressions, which have 6 or 7 fields:
┌───────────── second (0-59)
│ ┌───────────── minute (0-59)
│ │ ┌───────────── hour (0-23)
│ │ │ ┌───────────── day of month (1-31)
│ │ │ │ ┌───────────── month (1-12)
│ │ │ │ │ ┌───────────── day of week (0-7, 0 and 7 are Sunday)
│ │ │ │ │ │ ┌───────────── year (optional)
│ │ │ │ │ │ │
* * * * * * *
0 0 12 * * ?- Every day at noon0 15 10 ? * MON-FRI- 10:15 AM every weekday0 0/5 14 * * ?- Every 5 minutes starting at 2:00 PM and ending at 2:55 PM, every day0 0 12 1/5 * ?- 12:00 PM every 5 days every month, starting on the first day of the month
Full Javadoc API documentation is available in the docs/ directory. Open docs/index.html in your web browser to view the complete documentation.
To update the documentation after making code changes:
mvn javadoc:javadoc
rsync -av target/reports/apidocs/ docs/- Java 11+
- Quartz Scheduler 2.3.2