need to restart cups to reach network printers

21,666

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
Share:
21,666

Related videos on Youtube

nightcod3r
Author by

nightcod3r

I cod3, at night.

Updated on September 18, 2022

Comments

  • nightcod3r
    nightcod3r over 1 year

    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?

    • Admin
      Admin over 7 years
      @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.
    • Admin
      Admin over 7 years
      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. superuser.com/questions/280396/…
    • Admin
      Admin over 7 years
      Is Ubuntu the exact same version as before? For detection, the various lp* commands may indicate what CUPS can see.
    • Admin
      Admin over 7 years
      @thrig right, lpq -l might do it. I was using Ubuntu 14.04.
    • Admin
      Admin over 7 years
      @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.
    • Admin
      Admin over 7 years
      @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.