Skip to content

Instantly share code, notes, and snippets.

@CarlosDomingues
Created March 21, 2022 13:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CarlosDomingues/97098c62b448fed61397444e83b88cbb to your computer and use it in GitHub Desktop.
Save CarlosDomingues/97098c62b448fed61397444e83b88cbb to your computer and use it in GitHub Desktop.
systemd timers example

A simple example of systemd timers. Inspired by this blog post.

1 - Go to /etc/systemd/system

2 - Create a FreeMemoryStatistics.service unit file like so:

[Unit]
Description=Logs free memory statistics to the systemd journal
Wants=FreeMemoryStatistics.timer

[Service]
Type=oneshot
ExecStart=/usr/bin/free

[Install]
WantedBy=multi-user.target

3 - Create a FreeMemoryStatistics.timer unit file like so:

[Unit]
Description=Logs free memory statistics to the systemd journal
Requires=FreeMemoryStatistics.service

[Timer]
Unit=FreeMemoryStatistics.service
OnCalendar=*-*-* *:*:00

[Install]
WantedBy=timers.target

4 - Start the service: sudo systemctl start FreeMemoryStatistics.service

5 - You should see the output of the free command being executed every minut: journalctl -S today -f -u FreeMemoryStatistics.service

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment