Featured image of post Creating systemd Timers via CLI – Simple, Fast, Hassle-Free

Creating systemd Timers via CLI – Simple, Fast, Hassle-Free

A handy little tool that generates systemd .service and .timer units via CLI – a modern alternative to cron.

If you’ve ever tried writing systemd timers by hand, you know: it’s not exactly fun. Between .service and .timer files, path syntax, and OnCalendar expressions, it’s easy to get lost. That’s why I built a small tool: systemd-timer.

What does it do?

It’s simple: You call a CLI command, provide a few arguments, and the tool writes the appropriate .service and .timer files for you — with logging, dependencies, and all the systemd details you’d otherwise have to remember. No copy-pasting templates, no typos, no wondering whether it’s WantedBy=timers.target or not.

Why not just use cron?

Sure, cron works. But systemd has some clear advantages:

  • Better logging (including to file)
  • Easier integration with other services (like waiting for network)
  • Works per-user (no root needed)
  • Everything stays in one ecosystem: systemd

This CLI lowers the entry barrier while still encouraging “proper” systemd usage.

What can systemd-timer do?

  • Generates .service + .timer unit files

  • Supports --user timers (great for desktop or containers)

  • Logging to file via --logfile

  • Standard options like:

    • --exec, --calendar, --after, --environment
    • --description, --output, --dry-run
  • CLI built with Cliffy, typed with Deno

  • Platform-independent install via shell script

A quick example

1
2
3
4
5
6
systemd-timer create \
  --exec "/usr/local/bin/backup.sh" \
  --calendar "Mon..Fri 02:00" \
  --description "Backup Job" \
  --user \
  --logfile "/var/log/backup.log"

This creates:

  • ~/.config/systemd/user/backup.service
  • ~/.config/systemd/user/backup.timer

To activate:

1
2
systemctl --user daemon-reload
systemctl --user enable --now backup.timer

One-liner install

1
curl -fsSL https://git.0xmax42.io/maxp/systemd-timer/raw/branch/main/scripts/install.sh | sh

The script auto-detects your architecture (amd64/arm64), fetches the right binary, and verifies it via SHA256. And yes, you can inspect the code before piping it into your shell.

Development & testing

The tool is written entirely in TypeScript with Deno, strictly typed and covered by tests. The core is modular enough that you could use it as a library if needed.

Run tests with:

1
deno task test

Conclusion

systemd-timer isn’t a monster with 1000 options — it’s just what you want when you need a clean way to run small systemd-timed tasks without rewriting the same files over and over. It’s aimed at people who prefer declarative setups over improvisation.

Source code, releases, and more: 👉 git.0xmax42.io/maxp/systemd-timer

Built with Hugo
Theme Stack designed by Jimmy