I would look into using incrontab for monitoring changes to the file system, and combine that with the little script you already have.
This looks approximately as follows.
First, save the script that you want to execute as a file, e.g. as cups_monitor.sh
in /usr/local/bin
(don't forget to make it executable).
#!/bin/sh VAR=`tail -n 1 /var/log/cups/error_log | grep 'client-error-not-possible for Create-Job'` if [[ -n "$VAR" ]]; then echo "$VAR" | DISPLAY=:0 notify-send -t 30000 -i fi
You might want to check this. My scripts are never right first try :). Also note that it is possible that this script does not capture your error message if it is followed by other message: I only look at the last line of the log file (-n 1
); this should be easy to change.
Then edit your incrontab
incrontab -e
by adding the line
/var/log/cups/error_log IN_CLOSE_WRITE /usr/local/bin/cups_monitor.sh
The IN_CLOSE_WRITE
is called an 'event symbol' and indicates that you want to want to call your script when/var/log/cups/error_log
was closed after it was opened for writing; you can find other events in the man page of incrontab.
Keep in mind that I did not test this. You can see whether the incrontab file was changed successfully and whether it calls your script or not by looking in the syslog (tail /var/log/syslog
).
(My first answer on Stack Exchange ever! Yippee!)