The answer from Janne above, e.g. this:
* * * * * lpstat -p |grep "poissa käytöstä" && service avahi-daemon restart; service cups restart; cupsenable HP_Tuloostin
... will cause CUPS to be restarted every minute, regardless of what state any printer is in. That's because the cups restart clause is not paired with the &&.
Here is a short BASH script I used to make restarting CUPS conditional upon detecting a failure state.
#!/bin/bash
DATE=$(date)
DS40=$(/usr/bin/lpstat -p |grep "DS40" |grep "disabled")
if [ ! -z "${DS40}" ]; then
echo "${DATE} - Restarted avahi and cups" >> /var/log/cups/restart-cron-tim.log
/usr/sbin/service avahi-daemon restart
/usr/sbin/service cups restart
/usr/sbin/cupsenable Dai_Nippon_Printing_DS40
fi
Replace "DS40" with whatever printer you're looking for the status of, and "disabled" with whatever lpstat -p outputs in your language.
What is causing this: For one, when my wifi printer is powered down it seems to clear the Enabled flag. Even when the printer is powered back up the Enabled flag is not restored to checked. .. ---Jobs will then pile up in the print queue. The error message is "filter failed". When I check this box in printer settings the printer starts printing again. – Elliptical view – 2016-10-08T21:00:29.933