<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/">
	<channel>
		<title>Systemd on Connectemoi.eu</title>
		<link>https://connectemoi.eu/tags/systemd/</link>
		<description>Recent content in Systemd on Connectemoi.eu</description>
		<generator>Hugo -- 0.161.1</generator>
		<language>en</language>
		<lastBuildDate>Tue, 07 Jul 2026 10:57:35 +0200</lastBuildDate>
		<atom:link href="https://connectemoi.eu/tags/systemd/index.xml" rel="self" type="application/rss+xml" />
		
		
		<item>
			<title>Systemd Timer</title>
			<link>https://connectemoi.eu/posts/systemd-timer/</link>
			<pubDate>Tue, 07 Jul 2026 10:57:35 +0200</pubDate><guid>https://connectemoi.eu/posts/systemd-timer/</guid>
			<description><![CDATA[How to create a timer using systemd]]></description><content type="text/html" mode="escaped"><![CDATA[<p>Systemd execute a service at a planned time described in a timer.
In order to run a script at 2 am we need to create a service and a timer.</p>
<h1 id="create-a-service-file">Create a service file<a href="#create-a-service-file" class="anchor" aria-hidden="true"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
      stroke-linecap="round" stroke-linejoin="round" class="feather">
      <path d="M15 7h3a5 5 0 0 1 5 5 5 5 0 0 1-5 5h-3m-6 0H6a5 5 0 0 1-5-5 5 5 0 0 1 5-5h3"></path>
      <line x1="8" y1="12" x2="16" y2="12"></line>
   </svg></a></h1>
<pre tabindex="0"><code>#/etc/systemd/system/myscript.service
[Unit]
Description=Run a script daily at 2am
After=network.target

[Service]
Type=oneshot
ExecStart=/bin/bash /myscript.sh
WorkingDirectory=/
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target
</code></pre><h1 id="create-a-timer">Create a timer<a href="#create-a-timer" class="anchor" aria-hidden="true"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
      stroke-linecap="round" stroke-linejoin="round" class="feather">
      <path d="M15 7h3a5 5 0 0 1 5 5 5 5 0 0 1-5 5h-3m-6 0H6a5 5 0 0 1-5-5 5 5 0 0 1 5-5h3"></path>
      <line x1="8" y1="12" x2="16" y2="12"></line>
   </svg></a></h1>
<pre tabindex="0"><code>#/etc/systemd/system/myscript.timer
[Unit]
Description=Run the service every day at 2am

[Timer]
OnCalendar=*-*-* 02:00:00
Persistent=true
RandomizedDelaySec=60

[Install]
WantedBy=timers.target
</code></pre><h1 id="reload-the-systemd-daemon-and-enable-the-timer">Reload the systemd daemon and enable the timer<a href="#reload-the-systemd-daemon-and-enable-the-timer" class="anchor" aria-hidden="true"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
      stroke-linecap="round" stroke-linejoin="round" class="feather">
      <path d="M15 7h3a5 5 0 0 1 5 5 5 5 0 0 1-5 5h-3m-6 0H6a5 5 0 0 1-5-5 5 5 0 0 1 5-5h3"></path>
      <line x1="8" y1="12" x2="16" y2="12"></line>
   </svg></a></h1>
<pre tabindex="0"><code>sudo systemctl daemon-reload
sudo systemctl enable --now myscript.timer
</code></pre><h1 id="verify">Verify<a href="#verify" class="anchor" aria-hidden="true"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
      stroke-linecap="round" stroke-linejoin="round" class="feather">
      <path d="M15 7h3a5 5 0 0 1 5 5 5 5 0 0 1-5 5h-3m-6 0H6a5 5 0 0 1-5-5 5 5 0 0 1 5-5h3"></path>
      <line x1="8" y1="12" x2="16" y2="12"></line>
   </svg></a></h1>
<pre tabindex="0"><code>sudo systemctl status myscript.timer
systemctl list-timers myscript.timer
</code></pre><p>We can run the timer right now and verify the logs:</p>
<pre tabindex="0"><code>sudo systemctl start myscript.service
sudo journalctl -u myscript.service | tail -20
</code></pre><h1 id="disable-a-timer-">Disable a timer :<a href="#disable-a-timer-" class="anchor" aria-hidden="true"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
      stroke-linecap="round" stroke-linejoin="round" class="feather">
      <path d="M15 7h3a5 5 0 0 1 5 5 5 5 0 0 1-5 5h-3m-6 0H6a5 5 0 0 1-5-5 5 5 0 0 1 5-5h3"></path>
      <line x1="8" y1="12" x2="16" y2="12"></line>
   </svg></a></h1>
<pre tabindex="0"><code>sudo systemctl disable --now myscript.timer
</code></pre>]]></content>
		</item>
		
	</channel>
</rss>
