Jiff Slater
🤔 About
✍️ Contact
30 Jul 2021
These articles have been archived. You may find them useful but I am no longer offering support for them. Check out my latest articles on plkt.io.
Moving a user cron job to a systemd timer
23 March 2019

I have been using cron for well over a decade to schedule tasks to run when I’m not logged in. However, maintaining logs for these has been difficult and, after using systemd for a while, think I should switch to using a timer.

First, take a look at your current cron jobs.

$ crontab -l
0 * * * * offlineimap

This syncs my email every hour on the hour. For an equivalent systemd implementation we need to write a timer and a service. The timer will call the service at the scheduled time.

# $HOME/.config/systemd/user/offlineimap.service
Description=Local offlineimap service



# $HOME/.config/systemd/user/offlinemap.service.d/01-env.conf
# There is no shell expansion here.
# Don't surround the values with quotes.


# $HOME/.config/systemd/user/offlineimap.timer
Description=Sync mail using IMAP every hour



Now we can load these new units with “systemctl –user daemon-reload” and start them with “systemctl –user enable offlineimap.timer”.

Further reading: UNIX and Linux System Administration Handbook (5th Edition) [Amazon]