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.
Description=Local offlineimap service
# There is no shell expansion here.
# Don't surround the values with quotes.
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]