How to Schedule pmgspamreport in Proxmox Mail Gateway


How to Schedule pmgspamreport in Proxmox Mail Gateway

Proxmox 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.


1. What is a systemd timer?

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:

  • More detailed and flexible scheduling
  • Easily monitor service status and logs
  • Modern, system-level alternative to cron

2. Setting Up the pmgspamreport Timer

2.1. Create the Timer File

First, 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.


2.2. Create the Service 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.


3. Enable and Start 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 units
  • enable: Ensures the timer starts at boot
  • start: Starts the timer immediately

4. Verifying the Timer

Check 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! 🎉


5. Testing the Timer Manually

To test the service manually:

systemctl start pmgspamreport.service

To check logs:

journalctl -u pmgspamreport.service --since "5 minutes ago"

✅ Summary

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:

  • Created the timer file: /etc/systemd/system/pmgspamreport.timer
  • Created the service file: /etc/systemd/system/pmgspamreport.service
  • Enabled and started the timer
  • Verified execution times and logs

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.


0 Votes: 0 Upvotes, 0 Downvotes (0 Points)

Leave a reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Son yorumlar
No comments to show.
Bize Katılın
  • Facebook38.5K
  • X Network32.1K
  • Behance56.2K
  • Instagram18.9K

En Son ve En Önemli Haberlerden Haberdar Olun

I consent to receive newsletter via email. For further information, please review our Privacy Policy

Kategoriler

Reklam

Loading Next Post...
Takip et
Sign In/Sign Up Search
Popüler
Loading

Signing-in 3 seconds...

Signing-up 3 seconds...