Is there any frameworks / GUI to setup an alarm that triggers whenever mail is sent to /var/mail on ubuntu server? I'm currently using localhost because of closed network connection, and only way that I can access the server is using ssh. My current way of using this is to just use mutt whenever I care, but if there is an alarm trigger it would be very helpful for me - via SSH or something else.
Restrictions:
Any ideas or frameworks? Thanks.
#!/bin/bash
# Monitor /var/mail directory for changes
inotifywait -m /var/mail -e create -e moved_to |
while read path action file; do
# When a new file (mail) is created or moved into /var/mail, notify
notify-send "New mail received in /var/mail" "Check your mailbox."
done
Save this script, for example as mail_notification.sh, and make it executable (chmod +x mail_notification.sh). Setting up Notifications:
Ensure notify-send is installed on your server. It’s usually part of the libnotify-bin package, which you can install via sudo apt-get install libnotify-bin if not already installed. Adjust the script path and permissions as needed (chmod +x mail_notification.sh). Running the Script:
Run the script in a detached session or within a screen session on your server to keep it running even after you disconnect from SSH.