A flexible cron job scheduler with Telegram bot integration for notifications and control.
- Schedule and run cron jobs with customizable schedules
- Telegram bot integration for notifications and control
- Support for command execution and monitoring
- Optional webhook support for enhanced bot interaction
- Real-time job execution notifications
- Command-based job management
The following commands are available through the Telegram bot:
/list
- List all scheduled jobs with their names and schedules/run <name>
- Run a specific job immediately by its name/status
- Show currently running jobs and their duration
Create a YAML configuration file with the following structure:
bot: telegram
bot.telegram:
bot_token: your_bot_token_here
chat_id: your_chat_id_here
# Optional webhook URL (must be HTTPS), used to tell telegram
webhook: "https://example.com/tgbot"
# Required if webhook is set, used to setup listening
webhook_path: "tgbot"
# Required if webhook is set, used to setup listening
webhook_port: 8080
jobs:
# Run backup at 5 AM daily
- name: daily-backup
cron: "0 0 5 * * *"
program: rsync
args:
- "-av"
- "/path/from"
- "/path/to"
# Run system update check every 6 hours
- name: system-update
cron: "0 0 */6 * * *"
program: apt-get
args:
- "update"
bot
: The type of bot to use (currently only 'telegram' is supported)bot.telegram
: Telegram-specific configurationbot_token
: Your Telegram bot token from BotFatherchat_id
: Your Telegram chat idwebhook
: (Optional) HTTPS URL where Telegram will send updates
jobs
: List of jobs to schedulename
: Name of the job, must be unique, format[0-9a-zA-Z_-]+
cron
: Cron expression in format "second minute hour day month weekday"program
: The program to executeargs
: List of arguments to pass to the program
- Create a config file based on the example above
- Run the service:
./cronjobs /path/to/config.yaml
go build -o cronjobs cmd/cronjobs/main.go
Build the Docker image:
docker build -t go-cron-job .
Run with Docker:
docker run -v /path/to/config.yaml:/etc/cronjobs/config.yaml go-cron-job
To enable webhook mode:
- Ensure you have a domain with SSL certificate (required by Telegram)
- Add the webhook URL to your config file:
bot.telegram: webhook: "https://your.domain.com/path"
- Make sure your domain is accessible
- The service will automatically set up the webhook with Telegram
The webhook server will listen on port 8443 (required by Telegram).
- Only the configured Telegram chat id can interact with the bot
- Webhook mode requires HTTPS (SSL/TLS certificate)
- Keep your bot token secret and secure
- Be careful with job permissions, as they run with the service's privileges