You will, from time to time, feel the need to run a command at a specific time.
at(1) will run a command at a specified time, so if you need a reminder that you should go to bed at midnight, you could run the following command:
$ at midnight
at> echo Go to bed | wall ^D
If you instead need to run a command at regular times, such as a backup job, then you can add a persistent timed job with crontab(1).
You would run crontab -e
to add a command to your crontab,
as described in crontab(5).
To run nightly obnam backup (instructions taken from Bastian Rieck's blog), add the following to the crontab file.
0 20 * * * /usr/bin/obnam backup $HOME
This could instead be written as a systemd timer unit, which can be used without a separate cron service running, by creating two configuration files as follows:
$ mkdir -p ~/.config/systemd/user
$ cat >~/.config/systemd/user/backup.timer <<'EOF'
> [Unit]
> Description=Backup timer
> [Timer]
> OnCalendar=daily
> [Install]
> WantedBy=default.target
> EOF
$ cat >~/.config/systemd/user/backup.service <<'EOF'
> [Unit]
> Description=Backup Service
> [Service]
> Type=simple
> ExecStart=/usr/bin/obnam backup %h
> [Install]
> WantedBy=default.target
> EOF
$ systemctl --user daemon-reload
$ systemctl --user enable backup.timer backup.service
$ systemctl --user start backup.timer backup.service
This is more verbose than the cron syntax, though arguably less arcane.
However systemd timer units have the advantage
of allowing you to set WakeSystem=
,
which will unsuspend your system to react to timer events.
There are instructions on how to use this to make an alarm clock on Joey Hess' blog.