No description
Find a file
kekskurse 01e283f96b
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
feat: gotify notification
2025-07-31 18:43:03 +02:00
scripts fix: installation script for deb 2025-07-31 03:50:27 +02:00
vendor init 2025-07-31 03:01:56 +02:00
.gitignore ci: goreleaser 2025-07-31 03:23:35 +02:00
.goreleaser.yml ci: test 2025-07-31 03:44:54 +02:00
.woodpecker.yml ci: gitea token secret 2025-07-31 03:36:05 +02:00
config.go feat: gotify notification 2025-07-31 18:43:03 +02:00
config.yml.example ci: test 2025-07-31 03:44:54 +02:00
config_test.go init 2025-07-31 03:01:56 +02:00
error.go init 2025-07-31 03:01:56 +02:00
go.mod init 2025-07-31 03:01:56 +02:00
go.sum init 2025-07-31 03:01:56 +02:00
gotify.go feat: gotify notification 2025-07-31 18:43:03 +02:00
jobResult.go feat: gotify notification 2025-07-31 18:43:03 +02:00
main.go feat: gotify notification 2025-07-31 18:43:03 +02:00
README.md feat: gotify notification 2025-07-31 18:43:03 +02:00
time.go init 2025-07-31 03:01:56 +02:00
timer_test.go init 2025-07-31 03:01:56 +02:00

SCRON

A lightweight, efficient cron-like scheduler written in Go that executes shell commands at specified intervals with precise timing and comprehensive logging.

Features

  • Flexible Scheduling: Schedule jobs using minute and hour patterns with wildcard support
  • Configuration Reloading: Monitors config file changes for dynamic job updates
  • Comprehensive Logging: Detailed execution logs using zerolog with configurable levels
  • Error Handling: Robust error handling with exit code tracking and output capture
  • Shell Command Support: Execute any shell command via bash
  • Notifications: Send job status notifications via Gotify

Installation

Download the latest .deb package from the releases page and install:

Install package

sudo dpkg -i scron_X.X.X_linux_amd64.deb

Configuration file at /etc/scron/config.yml

Configuration

Create a config.yml file in the same directory as the binary (or /etc/scron if install via .deb):

jobs:
  - name: "Daily Backup"
    minute: "0"
    hour: "2"
    command: "backup.sh /data /backup"
  
  - name: "Health Check"
    minute: "*/5"
    hour: "*"
    command: "curl -f http://localhost:8080/health"
  
  - name: "Log Cleanup"
    minute: "30"
    hour: "1"
    command: "find /var/log -name '*.log' -mtime +7 -delete"

Configuration Fields

|| Field | Description | Format | Examples | ||-------|-------------|--------|----------| || name | Descriptive job name for logging | String | "Daily Backup", "Health Check" | || minute | Minute pattern (0-59) | String | "0", "*/5", "15,30,45", "*" | || hour | Hour pattern (0-23) | String | "2", "*/2", "9-17", "*" | || command | Shell command to execute | String | "echo 'Hello'", "backup.sh" | || notification | Name of notification configuration to use | String | "default" |

Notifications

You can configure notifications for job success or failure using Gotify:

notification:
  - name: default
    success:
      gotify:
        url: https://gotify.example.com/message?token=YOUR_TOKEN
    error:
      gotify:
        url: https://gotify.example.com/message?token=YOUR_TOKEN

jobs:
  - name: "Daily Backup"
    minute: "0"
    hour: "2"
    command: "backup.sh /data /backup"
    notification: default

Notifications support:

  • Multiple named notification configurations
  • Separate success and error notification URLs
  • Optional configuration per job

Pattern Syntax

  • * - Every minute/hour
  • */n - Every n minutes/hours
  • n - Specific minute/hour
  • n,m,o - Multiple specific values
  • n-m - Range of values

Examples

Simple Periodic Task

jobs:
  - name: "Heartbeat"
    minute: "*"
    hour: "*"
    command: "echo $(date): Service running >> /var/log/heartbeat.log"

Business Hours Only

jobs:
  - name: "Business Hours Check"
    minute: "0"
    hour: "9-17"
    command: "business-hours-task.sh"

Multiple Schedules

jobs:
  - name: "Frequent Check"
    minute: "*/2"
    hour: "*"
    command: "quick-check.sh"
  
  - name: "Hourly Report"
    minute: "0"
    hour: "*"
    command: "generate-report.sh"
  
  - name: "Daily Cleanup"
    minute: "0"
    hour: "3"
    command: "cleanup.sh"