Skip to content

TechDirectArchive

Hands-on IT, Cloud, Security, Veeam & DevOps

  • Home
  • About
  • Advertise With US
  • Reviews
  • Contact
  • Toggle search form

How to use Systemd Timers on Linux

Posted on 22/07/202216/08/2026 ShatteredEmblem By ShatteredEmblem No Comments on How to use Systemd Timers on Linux
  1. Home
  2. Linux
  3. How to use Systemd Timers on Linux
systemd_services

A systemd timer is a unit configuration file that provides a simple and effective way to schedule tasks on Linux. These timers offer an alternative to cron jobs and are the newer method of triggering jobs at specified times. Timer files, just like service files, are units controlled by systems. In this article, you will learn how to use Systemd Timers on Linux. Please see How to install Golang on a Linux System, How To Install Google Cloud SDK on a Linux System, and how to install and configure Elasticsearch on Linux.

The following guide will demonstrate how to run a simple bash script, at regular intervals, using a systemd timer. Here are further interesting guides: A brief Introduction to Linux and how to create disk partition in Ubuntu Linux, and how to Install Terraform on Linux, How to install AnyDesk on a Linux Machine,

Why use systemd timers as a task scheduler?

Systemd timers offer the best of both cron and anacron thereby allowing scheduling down to minute granularity. The following are some key reasons to use systemd timers.

  • Systemd is a standard on most modern Linux systems and timers are a well-integrated part of it, so there is no need to install another package.
  • Systemd distributions use systemd-journald for collecting and logging data. It leverages journalctl for querying the contents of the systemd journal just like any other unit logs. This makes debugging easier.
  • Jobs can be run manually simply using systemctl start.
  • Jobs can be tested without waiting for the schedule.
  • Jobs can have complex dependencies and be set up to depend on other systemd units, meaning, a timer can be triggered relative to when other services were activated or deactivated, on machine boot, etc.

Prerequisites on how to Systemd Timers on Linux

The following prerequisite must be met in order to use systemd timers effectively.

  • Root privileges
  • Terminal
  • Basic systemd knowledge

Setting up a systemd timer

Systemd timers consist of two main configuration files:

  • Service files are unit configuration files that define and manage systems processes. They use the .service suffix.
  • Timers manage when to run these service files. Timer files end in .timer

Create a test script

First, let’s create a basic bash script to run as an example. We will use the vi editor to do this.

sudo vi /usr/local/bin/test.sh

The script will simply print out the date through an echo command.

Bashscript
Bash file for testing

Please see Linux Boot Process Explained Step by Step for Beginners, Elasticsearch: How to stop systemd service start operation from timing out, and how to Create Service Accounts, Organisation Units and Active Directory Security Groups.

Service file

Now, create a service file to execute this bash script. We will do this under:

sudo vi /etc/systemd/system/test.service
Servicefile
Service config file

From the top, we first define the unit marker and provide a simple description of what the unit is doing.

Then, we define a service of type simple, which means that the command declared in ExecStart is the main process of the service. ExecStart will run the specified command. Lastly, the service will restart in case of failure.

Timer file

The next step is to create a timer file.

sudo vi /etc/systemd/system/test.timer
Timerfile
Timer config file


Again, we have a description to explain what the unit does. With the OnCalendar option, we select the time we want to run the script. In this case, the timer will run everyday at 7 pm. The calendar timing format is quite simple. It is a YYY-MM-DD HH:MM:SS format.

However, a particular day can also be specified. For instance, if you want to set the service to run every Monday at 3 am, it would be:  Mon *-*-* 03:00:00

Finally, under install, we specify multi-user.target, which indicates that the service should start at runlevels 3, 4, and 5. This option is only set when a service is enabled with systemctl.

Also, see how to Delete or Rename and Create a Protected Organisation Unit in AD, Create and find Organisation Unit paths in AD, and How to access shared resources from two different domains.

Start and enable the timer

The final step is to start and enable the timer. We do this using systemctl. However, we must do a daemon-reload. This will reload the system files in case any new unit files were created or edited.

sudo systemctl daemon-reload

Then we start the timer. We also enable it, so it’s automatically started on boot. The timer then calls the service when scheduled.

sudo systemctl start test.timer
sudo systemctl enable test.timer

To make sure the timer is running, use the following command:

sudo systemctl status test.timer
timestatus
Status of systemd timer

The output shows us whether the timer is running based on its active status. In this case, the timer is active but waiting, indicating that it’s waiting for the next time it will run.

What’s more interesting is the trigger part. This displays the time of the next trigger and how long is left. In this case, in 7 hours. It also shows which service the timer triggers.

Other useful commands

We can find even more information about our timers and services using certain commands. The following command can be used to check if the service was successfully executed:

sudo journalctl -S today -f -u test.service
servicetest
Result of journal logs

The result shows when the service last started and the output of the bash script.

Next, the systemd-analyze tool converts a relative calendar time expression into its normalized form. We can use this command to ensure our OnCalender value is accurate, and by picking a date in the future, we can also check when a timer will start next.

systemd-analyze calendar 2022-07-25
systemdanalyzse
Result of system analyze command

Another useful command displays all the timers on a system.

sudo systemctl list-timers --all
List-timers
Showing all timers on the system

Here, we can see all our timers, the services associated with them, and when they will next fire.

Conclusion on how to use Systemd Timers on Linux

It is very easy to get started with systemd timers right out of the box. As demonstrated, with only a few steps, a fully automated scheduling job was created and ready to go. Timers can be created for many different jobs such as updates, backups, disk clean-ups, scripts, and more.

I hope you found this blog post helpful. If you have any questions, please let me know in the comment section.

Thank you for reading this post. Kindly share it with others.

  • Share on X (Opens in new window) X
  • Share on Reddit (Opens in new window) Reddit
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on Facebook (Opens in new window) Facebook
  • Share on Pinterest (Opens in new window) Pinterest
  • Share on Tumblr (Opens in new window) Tumblr
  • Share on Telegram (Opens in new window) Telegram
  • Share on WhatsApp (Opens in new window) WhatsApp
  • Share on Mastodon (Opens in new window) Mastodon
  • Share on Bluesky (Opens in new window) Bluesky
Linux Tags:Task Scheduler

Post navigation

Previous Post: How to remove a Device from your Microsoft Account
Next Post: How to use a Fido Certified U2F Key for Authentication

Related Posts

  • whois4578uh
    How to get Domain information using WHOIS Command in Linux Linux
  • maxresdefault
    Linux Directory Hierarchy Linux
  • ubuntu 1479782 1280
    Ubuntu Linux post installation of Network Properties, Guest Integration and Web Administration using Cockpit Linux
  • prometheus feature image
    How to use Prometheus for Monitoring Linux
  • Screenshot 2020 05 14 at 17.47.09
    Configure OpenSSH Server: A Quick Guide Linux
  • Screenshot 2020 05 14 at 18.00.59
    Linux Error 13: Permission denied – Are you root Linux

More Related Articles

whois4578uh How to get Domain information using WHOIS Command in Linux Linux
maxresdefault Linux Directory Hierarchy Linux
ubuntu 1479782 1280 Ubuntu Linux post installation of Network Properties, Guest Integration and Web Administration using Cockpit Linux
prometheus feature image How to use Prometheus for Monitoring Linux
Screenshot 2020 05 14 at 17.47.09 Configure OpenSSH Server: A Quick Guide Linux
Screenshot 2020 05 14 at 18.00.59 Linux Error 13: Permission denied – Are you root Linux

Leave a Reply Cancel reply

You must be logged in to post a comment.

Microsoft MVP

vexpert-badge-stars-5

Virtual Background

VEEAMLEGEND

Categories

veeaam100

Veeam Vanguard

  • A connection to the deployment share could not be made Errors in MDT e1781960443644
    PCI Driver Error: Connection to Deployment Share could not be made Windows
  • Webp.net resizeimage 5
    How to Improve Website Response Using Traffic Manager AWS/Azure/OpenShift
  • WindowsTerminalServerRDS
    Remove a Remote Desktop Service collection Windows Server
  • Fix Network related MSSQL instance error
    Fix a network-related or instance-specific error occurred while establishing a connection to SQL Server [Part 2] Oracle/MSSQL/MySQL
  • FileNotFoundError Errno 2 No such file or directory
    Fix FileNotFoundError: [Errno 2] No such file or directory Scripts
  • greywireshark
    How to install WireShark on a Linux Ubuntu System Linux
  • Screenshot 2020 05 13 at 19.23.25
    AWS Command-Line Interface: How to configure AWS CLI [Part 1] AWS/Azure/OpenShift
  • screenshot 2020 02 13 at 22.47.41
    Active Directory Flexible Single-Master Operations Roles [FSMO] Windows Server

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1,752 other subscribers
  • RSS - Posts
  • RSS - Comments
  • About
  • Authors
  • Write for us
  • Contact
  • Advertise with us
  • General Terms and Conditions
  • Privacy policy
  • Feedly
  • Telegram
  • Youtube
  • Facebook
  • Instagram
  • LinkedIn
  • Tumblr
  • Pinterest
  • Twitter
  • mastodon
  • Bsky

Tags

Active Directory Azure Bitlocker Microsoft Windows PowerShell WDS Windows 10 Windows 11 Windows Deployment Services Windows Server 2016

Copyright © 2026 TechDirectArchive

Loading Comments...

You must be logged in to post a comment.