<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Cron on Besterry — Linux &amp; DevOps Notes</title><link>https://besterry.com/tags/cron/</link><description>Recent content in Cron on Besterry — Linux &amp; DevOps Notes</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Sat, 17 Feb 2024 00:00:00 +0000</lastBuildDate><atom:link href="https://besterry.com/tags/cron/index.xml" rel="self" type="application/rss+xml"/><item><title>systemd Timers vs Cron: When to Use Which</title><link>https://besterry.com/posts/systemd-timer-vs-cron/</link><pubDate>Sat, 17 Feb 2024 00:00:00 +0000</pubDate><guid>https://besterry.com/posts/systemd-timer-vs-cron/</guid><description>&lt;p&gt;Cron has been the standard scheduler on Unix for decades. systemd timers are newer, more powerful, but also more verbose.&lt;/p&gt;
&lt;h2 id="cron-wins-when"&gt;Cron wins when&lt;/h2&gt;
&lt;p&gt;Cron is perfect for one-line scripts that need to run on a simple schedule. Writing:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;0 3 * * * /usr/local/bin/backup.sh
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;is fast, requires no other files, and works on every Unix-like system since the 1970s.&lt;/p&gt;
&lt;h2 id="systemd-timers-win-when"&gt;systemd timers win when&lt;/h2&gt;
&lt;p&gt;You want any of these:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Logging integrated with journalctl&lt;/li&gt;
&lt;li&gt;Dependencies on other units (&lt;code&gt;After=network-online.target&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Resource limits (&lt;code&gt;MemoryMax=&lt;/code&gt;, &lt;code&gt;CPUQuota=&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Randomized delays to avoid thundering herd (&lt;code&gt;RandomizedDelaySec=&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;The ability to manually trigger with &lt;code&gt;systemctl start&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Catch-up behavior after system was off (&lt;code&gt;Persistent=true&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="minimal-systemd-timer-example"&gt;Minimal systemd timer example&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;/etc/systemd/system/backup.service&lt;/code&gt;:&lt;/p&gt;</description></item></channel></rss>