Skip to main content

Claude Prompt for a Cron Job Manager with Monitoring

Design a cron job management system with execution logging, failure alerting, overlapping-run prevention, and a status dashboard.

Vul de plaatshouders in

Edit the values, then copy your finished prompt.

Jouw Prompt
prompt.txt

                                

What this prompt does

This prompt builds a cron job management wrapper for a [environment_type] running [job_count] scheduled tasks. It creates a cron-runner.sh that logs stdout, stderr, exit code, and duration to [log_directory], flock-based locking to prevent overlapping runs with a [lock_timeout]-minute stale-lock guard, alerts via [alert_channel] on failure or overrun by [timeout_multiplier]x, a SQLite execution history, a status table over the past [history_days] days, log rotation keeping [retention_days] days gzipped, and a YAML-to-crontab generator.

The variables encode the guardrails. [lock_timeout] and [timeout_multiplier] define when a job is considered stuck or stale, [alert_channel] routes failure notifications, and [history_days] plus [retention_days] control how much history the status view and logs keep. The YAML config turns ad-hoc crontab lines into a reviewable file where each job declares its schedule, command, timeout, and recipients.

When to use it

  • You have been burned by silent cron failures or overlapping runs
  • You want per-run logging capturing exit code and duration for every job
  • Preventing overlapping executions with flock and a stale-lock timeout
  • Alerting when a job fails, runs late, or exceeds its expected runtime
  • You want a status command showing last run, last status, and failure rate
  • Turning ad-hoc crontab lines into a reviewable YAML config

Example output

Expect a cron-runner.sh wrapper, a flock locking mechanism, an alerting function targeting [alert_channel], a SQLite schema and insert logic for execution history, a status command rendering a table over [history_days] days, a logrotate-style config keeping [retention_days] days, and a generator that reads YAML and emits a crontab. Each piece is a focused script tied together by the runner.

Pro tips

  • Set [lock_timeout] longer than a job's worst-case runtime, or a legitimately long run gets killed as a stale lock
  • Tune [timeout_multiplier] against real durations; too low and you get false overrun alerts, too high and a hung job goes unnoticed
  • Route critical alerts through a channel you actually watch via [alert_channel] — a Slack message no one reads is not monitoring
  • Keep [retention_days] aligned with disk capacity in [log_directory]; verbose jobs can fill a partition faster than expected
  • Use the YAML-to-crontab generator as the single source of truth so cron changes go through review instead of manual edits
  • Have the status command surface failure rate over [history_days] so a job that fails intermittently is visible, not just hard-down jobs
  • Capture both stdout and stderr per run; the error you need during an incident is almost always on stderr, and a wrapper that only logs stdout hides it
  • Keep the SQLite history pruned in step with [retention_days] and rotate logs in [log_directory] so the management layer itself does not become the thing that quietly fills the disk it is meant to protect

Frequently Asked Questions

How does this stop the same cron job from running twice at once?
It wraps each job in flock-based locking so a second invocation cannot start while the first holds the lock. A configurable stale-lock timeout of `[lock_timeout]` minutes ensures a crashed run that never released its lock does not block the job forever.
Will it alert me if a job runs but takes far too long?
Yes. Besides failure alerts, it notifies you when a job exceeds its expected runtime by `[timeout_multiplier]`x, or has not run within its expected schedule window. This catches the silent cases where a job technically succeeds but hangs or is skipped entirely.
Why generate the crontab from YAML instead of editing it directly?
The YAML config makes each job's schedule, command, timeout, and alert recipients explicit and reviewable, then generates the crontab from it. This turns ad-hoc, error-prone crontab lines into something you can diff and review, reducing mistakes when many jobs are involved.
What does the SQLite database track?
It records every execution with job name, start time, end time, exit code, and output size. The status command then queries it to show last run time, last status, average duration, and failure rate over the past `[history_days]` days, giving you a history rather than just the latest run.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

Meer in Linux & Shell Scripting Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

Claude Code Expert · Online

👋

Hey there!

Quick Actions

WhatsApp Instant reply

Chat on WhatsApp

+880 1723 741224 · Instant reply

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

[email protected]

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support