<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: q8mrelm</title>
    <description>The latest articles on DEV Community by q8mrelm (@q8mrelm).</description>
    <link>https://dev.to/q8mrelm</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4271024%2F95070ce5-7de9-4825-b0a2-23be5c891a1a.png</url>
      <title>DEV Community: q8mrelm</title>
      <link>https://dev.to/q8mrelm</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/q8mrelm"/>
    <language>en</language>
    <item>
      <title>Your cron job stopped running 3 weeks ago. Here's how to find out in 5 minutes instead.</title>
      <dc:creator>q8mrelm</dc:creator>
      <pubDate>Sat, 28 Nov 2026 16:32:59 +0000</pubDate>
      <link>https://dev.to/q8mrelm/your-cron-job-stopped-running-3-weeks-ago-heres-how-to-find-out-in-5-minutes-instead-2bah</link>
      <guid>https://dev.to/q8mrelm/your-cron-job-stopped-running-3-weeks-ago-heres-how-to-find-out-in-5-minutes-instead-2bah</guid>
      <description>&lt;p&gt;Cron has one failure mode that hurts more than any crash: &lt;strong&gt;it fails silently&lt;/strong&gt;. The backup script exits 1, the server is rebuilt without the crontab, or someone comments out a line "for a minute". Nothing errors and nothing alerts. You find out when you need the backup.&lt;/p&gt;

&lt;p&gt;An HTTP uptime check can't catch this, because there is nothing to check from outside. The fix is to flip the direction: &lt;strong&gt;the job reports in, and silence is the alert.&lt;/strong&gt; This pattern is called heartbeat monitoring (also known as a dead man's switch).&lt;/p&gt;

&lt;h2&gt;
  
  
  The pattern
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Create a unique URL for each job.&lt;/li&gt;
&lt;li&gt;The job calls that URL when it finishes successfully.&lt;/li&gt;
&lt;li&gt;If no call arrives within the expected interval plus a grace period, you get alerted.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It catches every way a job can disappear: the crontab is gone, cron isn't running, the host is down, the job hangs, or the job exits early.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ping only on success
&lt;/h2&gt;

&lt;p&gt;The most common mistake is pinging unconditionally:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Wrong: pings even when the backup fails&lt;/span&gt;
0 2 * * * /opt/scripts/backup.sh&lt;span class="o"&gt;;&lt;/span&gt; curl -fsS https://example.com/ping
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; so the ping only happens when the script exits 0:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;0 2 * * * /opt/scripts/backup.sh &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; curl -fsS -m 10 --retry 3 https://example.com/ping &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /dev/null
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;-f&lt;/code&gt; makes curl fail on HTTP errors instead of printing an error page&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-sS&lt;/code&gt; is silent, but still shows errors&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-m 10 --retry 3&lt;/code&gt; stops a slow monitoring endpoint from hanging your cron&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Report failures explicitly
&lt;/h2&gt;

&lt;p&gt;Waiting for silence means waiting a full interval. If the job &lt;em&gt;knows&lt;/em&gt; it failed, say so immediately and include the exit code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;
&lt;span class="nv"&gt;BASE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"https://example.com/ping/YOUR_TOKEN"&lt;/span&gt;

curl -fsS -m 10 &lt;span class="s2"&gt;"$BASE/start"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /dev/null
/opt/scripts/backup.sh
&lt;span class="nv"&gt;code&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$?&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"$code"&lt;/span&gt; -eq 0 &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
  curl -fsS -m 10 &lt;span class="s2"&gt;"$BASE?exit_code=0"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /dev/null
&lt;span class="k"&gt;else&lt;/span&gt;
  curl -fsS -m 10 &lt;span class="s2"&gt;"$BASE/fail?exit_code=$code"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /dev/null
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="nb"&gt;exit&lt;/span&gt; &lt;span class="s2"&gt;"$code"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;/start&lt;/code&gt; call lets the monitor measure run duration. A job that normally takes 2 minutes and suddenly takes 40 is worth knowing about before it starts overlapping with itself.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pick the grace period honestly
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Job schedule&lt;/th&gt;
&lt;th&gt;Expected interval&lt;/th&gt;
&lt;th&gt;Grace period&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Every 5 minutes&lt;/td&gt;
&lt;td&gt;5 min&lt;/td&gt;
&lt;td&gt;2–5 min&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Hourly&lt;/td&gt;
&lt;td&gt;1 h&lt;/td&gt;
&lt;td&gt;10 min&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Nightly backup&lt;/td&gt;
&lt;td&gt;24 h&lt;/td&gt;
&lt;td&gt;30–60 min&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Weekly report&lt;/td&gt;
&lt;td&gt;7 d&lt;/td&gt;
&lt;td&gt;2–4 h&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Set the grace period to slightly more than the job's longest normal run time. If it's too tight you'll get false alarms, and you'll start ignoring them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Things that still bite people
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Cron's environment is minimal.&lt;/strong&gt; &lt;code&gt;PATH&lt;/code&gt; is usually &lt;code&gt;/usr/bin:/bin&lt;/code&gt;, so &lt;code&gt;curl&lt;/code&gt; may not be found on some systems. Use absolute paths, or set &lt;code&gt;PATH=&lt;/code&gt; at the top of the crontab.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Timezones.&lt;/strong&gt; Cron uses the system timezone. A server moved to UTC shifts every job, and your heartbeat will catch it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Overlapping runs.&lt;/strong&gt; Wrap long jobs in &lt;code&gt;flock -n /tmp/job.lock&lt;/code&gt; so a slow run doesn't stack up.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pinging from inside a &lt;code&gt;try&lt;/code&gt; block.&lt;/strong&gt; In application code, ping after the work commits, not before.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Tools
&lt;/h2&gt;

&lt;p&gt;You can build this yourself with a tiny endpoint and a timer, but the timer is the hard part: it has to be reliable when &lt;em&gt;your&lt;/em&gt; infrastructure isn't. Hosted options like &lt;a href="https://uptimeio.com/" rel="noopener noreferrer"&gt;UptimeIO&lt;/a&gt;, which I work on. UptimeIO's free plan includes heartbeat monitors next to regular website and API &lt;a href="https://uptimeio.com" rel="noopener noreferrer"&gt;uptime monitoring&lt;/a&gt;. Whichever you pick, the &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; and &lt;code&gt;/fail&lt;/code&gt; patterns above work the same way.&lt;/p&gt;

&lt;p&gt;How do you monitor your scheduled jobs? I'm curious whether anyone still relies on &lt;code&gt;MAILTO&lt;/code&gt;.&lt;/p&gt;

</description>
      <category>devops</category>
      <category>linux</category>
      <category>monitoring</category>
      <category>cron</category>
    </item>
  </channel>
</rss>
