# 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

### Recommended: Debian Package (.deb)

Download the latest `.deb` package from the [releases page](https://git.keks.cloud/kekskurse/scron/releases) 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):

```yaml
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:

```yaml
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
```yaml
jobs:
  - name: "Heartbeat"
    minute: "*"
    hour: "*"
    command: "echo $(date): Service running >> /var/log/heartbeat.log"
```

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

### Multiple Schedules
```yaml
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"
```
