sudo apt-get install heirloom-mail
- config your email address and MTA server in
send-mail.sh
sudo cp send-mail.sh /opt/send-mail.sh
sudo cp dummy.* /etc/systemd/system/
- execute
sudo systemctl start dummy.service
to confirm it works. sudo systemctl start dummy.timer
- Check the schedule via
systemctl list-timers
Created
March 20, 2020 08:19
-
-
Save hrchu/30a81b5a81a36af36678cc46d2d06bdf to your computer and use it in GitHub Desktop.
Daily report from systemd service/timer via email
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=A dummy service | |
[Service] | |
ExecStart=/bin/date # Replace this with your application | |
ExecStopPost=/opt/send-report.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=A dummy timer | |
[Timer] | |
OnCalendar=Daily | |
[Install] | |
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
mailx -v -s "Systemd service/timer report" -S smtp=smtp://[SMTP Server] -S from="[SENDER EMAIL]" [RECEIVER EMAIL] << EOF | |
$(journalctl --since "today" -u dummy) | |
EOF | |
echo 'Report sent. Bye for now.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment