Primeiro, crie um arquivo de serviço systemd em ~/.config/systemd/user/send-mail.service com o seguinte conteúdo:
[Unit]
Description=Sends mail that reminds me of an anniversary
[Service]
; The l flag for bash creates a login shell so Mutt can access our environment variables which contain configuration
ExecStart=/bin/bash -lc "echo \"$(whoami) created this message on $(date) to remind you about...\" | mutt -s \"Don't forget...\" [email protected]"
Você pode testar se o envio de mensagens funciona executando
systemctl --user daemon-reload && systemctl --user start send-mail.service
Isso deve enviar um email para [email protected] .
Em seguida, crie um timer em ~/.config/systemd/user/send-mail.timer com este conteúdo:
[Unit]
Description=Timer for writing mail to myself to remind me of anniversaries
[Timer]
; Trigger the service yearly on September 5th
OnCalendar=*-09-05
; Send a mail immediately when the date has passed while the machine was shut down
Persistent=true
AccuracySec=1us
; Set the timer to every ten seconds (for testing)
; OnCalendar=*:*:0/10
[Install]
WantedBy=timers.target
Observe que o conteúdo do timer não faz referência ao serviço. Ele ainda funciona porque o serviço e o timer têm o mesmo nome além dos sufixos .service e .timer . Se você quiser nomear o timer e o serviço de forma diferente, use Unit= na seção [Timer] do timer.
Faça seu temporizador iniciar na inicialização com
systemctl --user daemon-reload && systemctl --user enable send-mail.timer
Você deve poder ver o cronômetro agora com systemctl --user list-timers --all .
Para iniciar o cronômetro, faça
systemctl --user start send-mail.timer
Para verificar como o systemd interpreta suas datas, você pode usar systemd-analyze calendar *:0/2 ou systemd-analyze calendar quarterly .
Além disso, confira o manual no formato de horário do systemd.