Here's a more general use question.
How can I monitor a log file for specific changes, and use a "notify-send" alert in Ubuntu to alert when said changes occur?
I'm attempting to set up print quotas for printers here at the office. However, it appears when the quota is reached, the print just fails silently, and the user doesn't have any idea what's happening.
Page quota's set up by altering the PageLimit directive in /etc/cups/printers.conf
It appears I'm getting the message
E [04/Mar/2013:15:34:28 -0700] Returning IPP client-error-not-possible for Create-Job (ipp://localhost:631/printers/Hewlett-Packard-HP-LaserJet-4100-MFP) from localhost
in my log at /var/log/cups/error_log .
I tried hacking something together via a command like
`tail -f /var/log/cups/error_log | grep 'client-error-not-possible for Create-Job' DISPLAY=:0 notify-send -t 30000 -i 'notification-message-email' 'Printing Quota reached for this Printer'`
But that doesn't seem to really work as it only displays the message once on the first error message.
Any thoughts or solutions? It really seems like there should be a prebaked solution for this.
incrontab worked perfectly.
sudo apt-get install incrontab
Add user root to /etc/incron.allow
sudo nano /etc/incron.allow
Create script monitorCUPSlog.sh
#!/bin/bash tail -n 1 /var/log/cups/error_log | grep 'client-error-not-possible' | DISPLAY=:0 notify-send -t 30000 -i 'notification-message-email' 'Daily Print Quota exceeded for this printer'
And finally add the event to the incrontab table
sudo incrontab -e /var/log/cups/error_log IN_MODIFY /usr/local/bin/monitorCUPSlog.sh
Seems to work, yay.