pmgspamreport
in Proxmox Mail GatewayProxmox Mail Gateway (PMG) is a powerful solution for email security and filtering. PMG uses the pmgspamreport
service to send daily spam reports to users. By default, this service runs based on certain system events. If you prefer to run it at specific times, you can use a systemd timer.
In this article, you’ll learn how to configure a systemd
timer to automatically execute the pmgspamreport
service every day at 07:00, 09:00, 11:00, 13:00, 15:00, 17:00, and 19:00.
systemd
is a modern init system used on Linux systems to manage services. Unlike traditional cron
, systemd
timers allow precise control and monitoring of scheduled tasks.
Advantages of using systemd timers:
cron
pmgspamreport
TimerFirst, SSH into your PMG server and create the timer file:
nano /etc/systemd/system/pmgspamreport.timer
Insert the following content:
[Unit]
Description=Run pmgspamreport at specific times
[Timer]
OnCalendar=*-*-* 07:00:00
OnCalendar=*-*-* 09:00:00
OnCalendar=*-*-* 11:00:00
OnCalendar=*-*-* 13:00:00
OnCalendar=*-*-* 15:00:00
OnCalendar=*-*-* 17:00:00
OnCalendar=*-*-* 19:00:00
Persistent=true
[Install]
WantedBy=timers.target
This configuration schedules
pmgspamreport
to run seven times a day.
Save and close the file.
Next, define the service that the timer will execute:
nano /etc/systemd/system/pmgspamreport.service
Add the following content:
[Unit]
Description=Run pmgspamreport script
After=network.target
[Service]
Type=oneshot
ExecStart=/usr/sbin/pmgspamreport
[Install]
WantedBy=multi-user.target
This ensures the pmgspamreport
command runs when triggered by the timer.
Now reload the systemd configuration and enable the timer:
systemctl daemon-reload
systemctl enable pmgspamreport.timer
systemctl start pmgspamreport.timer
Explanation of the commands:
daemon-reload
: Reloads systemd to recognize new unitsenable
: Ensures the timer starts at bootstart
: Starts the timer immediatelyCheck the timer’s status and next run times:
systemctl list-timers --all | grep pmgspamreport
Example output:
Wed 2025-03-19 07:00:00 +03 6h left Wed 2025-03-18 19:00:00 +03 1h ago pmgspamreport.timer pmgspamreport.service
If the next run times match your configuration, everything is set up correctly!
To test the service manually:
systemctl start pmgspamreport.service
To check logs:
journalctl -u pmgspamreport.service --since "5 minutes ago"
In this guide, we scheduled the pmgspamreport
service in Proxmox Mail Gateway using systemd timers. Compared to cron
, systemd provides a more flexible and reliable way to schedule tasks.
To recap:
/etc/systemd/system/pmgspamreport.timer
/etc/systemd/system/pmgspamreport.service
This setup ensures that spam reports are automatically sent at your defined times. You can modify the OnCalendar
values to customize the schedule as needed.