Every once in a while (not necessarily after resuming from suspend or booting) I have to sudo /etc/init.d/cups restart to see again the network printers. Is there a way to bypass this process, or what is the best way to automate it under Lubuntu 16.04?
Asked
Active
Viewed 2.4k times
8
nightcod3r
- 952
- 2
- 16
- 32
-
Printing has always been fiddly in my experience. Perhaps use a nightly crontab job to bounce the service? – thrig Feb 01 '17 at 16:09
-
@thrig I thought of that, launching when it needs restart; but how to detect this situation? I had ubuntu installed in this machine before and this was not necessary, but yes, printing means trouble. – nightcod3r Feb 01 '17 at 16:27
-
In the configuration of CUPS (/etc/cups/printers.conf) for each printer there is an entry `ErrorPolicy`. If this is set to `stop-printer`, the printer que will be stopped when the printer (temporarily) is not reachable, what could happen with network printers. Set this to `retry-job`, so CUPS won't stop the queue and retry the print job later. See e.g. http://superuser.com/questions/280396/how-to-resume-cups-printer-from-command-line – ridgy Feb 01 '17 at 16:38
-
Is Ubuntu the exact same version as before? For detection, the various `lp*` commands may indicate what CUPS can see. – thrig Feb 01 '17 at 16:41
-
@thrig right, `lpq -l` might do it. I was using Ubuntu 14.04. – nightcod3r Feb 01 '17 at 17:48
-
@ridgy, not sure if I explained myself correctly. I meant that suddenly the printers are not there, when I try to print, they don't show, and only a `restart` brings them back to the list, and only now I can send a job. I.e., it is not a queuing problem. – nightcod3r Feb 01 '17 at 17:51
-
@ridgy Have checked, and the `printers.conf` file contains exactly the same information in both cases (when printers show up, and when they're hidden). So, the problem is that after some time, I try to print from, say, Chrome, and the network printers don't show up. After restarting CUPS they're back again in the list, and can send them jobs. – nightcod3r Feb 01 '17 at 20:26
1 Answers
2
For Linux based shell script you can try to schedule script as below:
Crontab entry:
*/5 * * * * sh /scripts/cups_recursive_checking.sh
#/bin/sh
HOST='server-name'
/etc/init.d/cups status>/scripts/cups.txt
if grep "cupsd (pid " /scripts/cups.txt
then
echo "cups is already running"
exit
else
/etc/init.d/cups restart
echo "cups just now started in server-name"
############# For mail Notification whenever cups gets restart follow below line according to your email ##########
mutt -e "my_hdr Content-Type: text/html" -e 'set realname=Notification' \
-e 'set [email protected]' [email protected] \
-s "CUPS Notification" < /scripts/cups.txt
fi
###END OF THE SCRIPT###
Example : To check the printers after the cups restart in Linux
lpstat -a
clientPrinter accepting requests since Sat 13 Jul 2019 10:07:01 AM IST
dmx accepting requests since Sat 13 Jul 2019 03:55:05 PM IST
HP_LaserJet_400_M401dw accepting requests since Sat 13 Jul 2019 03:05:06 PM IST
Scott - Слава Україні
- 10,332
- 10
- 39
- 68
Jagan Raj
- 21
- 3