Skip to main content

A Python3 script for checking syntax and correctness of crontab files

Project description

Checkcrontab - check syntax in crontab files

CI PyPI Python License

A Python script for checking syntax of crontab files. Cross-platform support for Linux, macOS, and Windows.

English | Español | Português | Français | Deutsch | Italiano | Русский | 中文 | 日本語 | हिन्दी

Requirements

  • Python 3.7 or higher
  • Linux: Linux system with systemctl (for daemon checks), read access to /etc/crontab
  • macOS: Unix system with read access to /etc/crontab (systemctl not available)
  • Windows: No additional requirements (file-based validation only)

Platform Support

Linux (Full Support):

  • ✅ System crontab validation (/etc/crontab)
  • ✅ User crontab validation (via crontab -l -u username)
  • ✅ User existence validation
  • ✅ Daemon/service checks via systemctl
  • ✅ All crontab syntax features
  • ✅ File permissions validation
  • ✅ Cron daemon status checks

macOS (Partial Support):

  • ✅ System crontab validation (/etc/crontab)
  • ✅ User crontab validation (via crontab -l -u username)
  • ✅ User existence validation
  • ❌ Daemon/service checks (systemctl not available)
  • ✅ All crontab syntax features
  • ✅ File permissions validation
  • ❌ Cron daemon status checks

Windows (Limited Support):

  • ✅ File-based crontab syntax validation
  • ❌ User existence checks (no user management integration)
  • ❌ System crontab access (no /etc/crontab)
  • ❌ Daemon/service checks (no systemctl)
  • ✅ All crontab syntax features supported
  • ❌ File permissions validation (no Unix permissions)
  • ❌ Cron daemon status checks (no cron daemon)

Installation

pip3 install checkcrontab

Or from GitHub:

pip3 install git+https://github.com/wachawo/checkcrontab.git

Usage

# Check system crontab (Linux/macOS only)
checkcrontab

# Check crontab file
checkcrontab /etc/crontab

# Check user crontab (Linux/macOS only)
checkcrontab username

# Check with explicit type flags
checkcrontab -S system.cron -U user.cron -u username1 -u username2

# Show help
checkcrontab --help

# Show version
checkcrontab --version

Platform-specific behavior:

  • Linux: Full functionality including daemon checks and user validation
  • macOS: Full functionality except daemon checks (systemctl not available)
  • Windows: File-based validation only, no system integration

TEXT Output

Чтобы перенаправить вывод из STDERR в STDOUT (например, для CI), используйте --format text:

checkcrontab --format text examples/user_valid.txt

SARIF Output

For SARIF output, use the --format sarif flag:

checkcrontab --format sarif examples/user_valid.txt

JSON Output

For machine-readable output, use the --format json flag:

checkcrontab --format json examples/user_valid.txt

Example JSON output:

{
  "success": true,
  "total_files": 2,
  "total_rows": 27,
  "total_rows_errors": 0,
  "total_errors": 0,
  "files": [
    {
      "file": "/etc/crontab",
      "is_system_crontab": true,
      "rows": 5,
      "rows_errors": 0,
      "errors_count": 0,
      "errors": [],
      "success": true
    },
    {
      "file": "examples/user_valid.txt",
      "is_system_crontab": false,
      "rows": 22,
      "rows_errors": 0,
      "errors_count": 0,
      "errors": [],
      "success": true
    }
  ]
}

Exit codes

Code Meaning
0 No errors (warnings allowed). With --exit-zero always 0.
1 Findings present: any error, or any warning when --strict is set.
2 Runtime/usage error (unexpected failure, bad CLI args, etc.).

Command Line Options

  • -S, --system - System crontab files
  • -U, --user - User crontab files
  • -u, --username - Usernames to check
  • -v, --version - Show version
  • -d, --debug - Debug output
  • -n, --no-colors - Disable colored output
  • --format {text,json,sarif} - Output format
  • --strict - Treat warnings as errors
  • --exit-zero - Always return exit code 0

Features

  • Cross-platform syntax validation (Linux, macOS, Windows)
  • Platform-specific features:
    • Linux/macOS: System and user crontab validation, user existence checks, daemon validation
    • Windows: File-based validation only
  • Time field validation (minutes, hours, days, months, weekdays)
  • Dangerous command detection
  • Special keyword support (@reboot, @daily, etc.)
  • Multi-line command support

Features Documentation - Comprehensive guide to supported syntax, valid values, examples, and error messages.

Development Tools

pip3 install pre-commit flake8 pytest mypy ruff
pre-commit install
pre-commit run --all-files
pre-commit autoupdate

Usage with pre-commit

You can use checkcrontab as a pre-commit hook in your projects:

  1. Add to your .pre-commit-config.yaml:
repos:
  - repo: https://github.com/wachawo/checkcrontab
    rev: 0.0.8  # Use the latest version
    hooks:
      - id: checkcrontab
        files: \.(cron|crontab|tab|conf)$
        exclude: (\.git|node_modules|__pycache__)/
        args: [--format, json, --strict]
  1. Install pre-commit:
pip install pre-commit
pre-commit install
  1. The hook will automatically check all .cron, .crontab, and .tab files in your repository.

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

checkcrontab-0.0.10.tar.gz (25.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

checkcrontab-0.0.10-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file checkcrontab-0.0.10.tar.gz.

File metadata

  • Download URL: checkcrontab-0.0.10.tar.gz
  • Upload date:
  • Size: 25.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for checkcrontab-0.0.10.tar.gz
Algorithm Hash digest
SHA256 d85f72dec01dd96bfecb2486e53911ec7bf9a1dcae1ca0adafffbf5dcf499efc
MD5 ea8345e4bc90b769ef09e47893ca582c
BLAKE2b-256 7c04812c49c6f5cad403db9c1b94447d4c0c238704c3796577f94264d0f9bb8c

See more details on using hashes here.

Provenance

The following attestation bundles were made for checkcrontab-0.0.10.tar.gz:

Publisher: publish.yml on wachawo/checkcrontab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file checkcrontab-0.0.10-py3-none-any.whl.

File metadata

  • Download URL: checkcrontab-0.0.10-py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for checkcrontab-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 8e8e5a70eadeadbe59b8c9fcfa8bf699442e35b22d8c2a37c1a2d5b6fa55a5e2
MD5 7a533800552eeaa70e48ce8af1b3ffa0
BLAKE2b-256 7d8f71399955405ee7619c1347815530b7f6c258784f0d05a8323eab1417b81a

See more details on using hashes here.

Provenance

The following attestation bundles were made for checkcrontab-0.0.10-py3-none-any.whl:

Publisher: publish.yml on wachawo/checkcrontab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page