How to resume CUPS printer from command line?

47

22

I have printer in CUPS that due to driver problems (HP 1010) from time to time goes into pause.

I would like to write a shell script that will execute once per hour to resume a printer in CUPS. But I have no idea after googling for couple of minutes how to resume printer from shell command line.

Stani

Posted 2010-03-03T13:25:43.687

Reputation: 609

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

Answers

68

There's the cupsenable command.

cupsenable printer

starts a disabled printer (to find out the printername you can list your printers with lpstat -p or lpc status).

You may have to run the command as root or through sudo. So if you have to enable the printer in a shell script, you would have to add the shell to root's crontab, or edit your sudoers file.

David V.

Posted 2010-03-03T13:25:43.687

Reputation: 811

1

+1 this answer in contrast to the "use the overbloated cups config" (as in https://superuser.com/a/280400/160771), really helped. Also its more to the point, since OP wanted to know command line

– humanityANDpeace – 2017-11-03T08:43:36.013

25

Your problem could be tackled in different ways, depending on the version of CUPS you're running.

  1. More recent versions of CUPS (version 1.2 and above) come with a builtin functionality that could help here. It's called "ErrorPolicy". It's default setting is selected in cupsd.conf, and determines how cupsd should handle print queues which do not behave as expected. You have 3 choices to tag to each queue individually:

    ErrorPolicy abort-job  
    ErrorPolicy retry-job  
    ErrorPolicy retry-this-job  
    ErrorPolicy stop-printer  
    

    Explanation:

    • abort-job
      -- Abort this job and proceed with next job in same queue

    • retry-job
      -- Retry this job after waiting for N seconds (where N is determined by cupsd.conf's "JobRetryInterval" directive).

    • retry-this-job
      -- Retry current job immediately and indefinitely.

    • stop-printer
      -- Stop current print queue and keep the job for future printing. This is still the default, unless you define otherwise as per above mentioned alternatives It also was default + only possible behaviour for all queues in previous versions of CUPS (the one you do want to get rid of as per your question).

    Additionally, you can set individual ErrorPolicies to each separate print queue. This setting would be noted in the printers.conf file. (Set it from a commandline with lpadmin -p printername -o printer-error-policy=retry-this-job).

  2. For older versions of CUPS I'd recommend to have a look at beh, the CUPS BackEnd Handler. beh is a wrapper which can be applied to any CUPS backend.

    Assuming your print queue currently has defined a backend of socket://192.168.1.111:9100, and it behaves in the way you don't like (being disabled by cupsd from time to time due to network connection problems). With beh you'd re-define your backend like this:

    beh:/0/20/120/socket://192.168.1.111:9100
    

    This would retry a job 20 times in two minute intervals, and disable the queue only when still not succeeding. Or you could do this:

    beh:/1/3/5/socket://192.168.1.111:9100
    

    This retries the job 3 times with 5 second delays between the attempts. If the job still fails, it is discarded, but the queue is not disabled. You want to let cupsd try indefinitely to connect to the device? Good, try this:

    beh:/1/0/30/socket://192.168.1.111:9100
    

    Try infinitely until printer comes back. Intervals between connection attempts are 30 seconds. The job does not get lost when the printer is turned off. You can intentionally delay printing simply by switching off the printer. A good configuration for desktop printers and/or home users.


Overall, there is no need to mess around with bash scripts, cron jobs, lpadmin, cupsenable or sudo in order to re-activate CUPS queues going down erratically.

Kurt Pfeifle

Posted 2010-03-03T13:25:43.687

Reputation: 10 024

How can we set the retry interval for more recent versions of CUPS? – Sepero – 2015-02-04T02:10:01.923

@Sepero: Yes. For example: you can try JobRetryInterval 58 to try every 58 seconds. Other possible values are 1w (1 week), 3d (3 days), 7h(7 hours) or 4m (4 minutes). – Kurt Pfeifle – 2015-02-04T10:50:13.860

@Sepero: *All* possible cupsd.conf parameters up to CUPS v1.7 are documented here: http://www.cups.org/documentation.php/doc-1.7/ref-cupsd-conf.html. Check the annotations for each parameter on the right edge of the page: it will tell you which CUPS release was the first to support it. Happy discovery of more useful params! :-)

– Kurt Pfeifle – 2015-02-04T10:54:14.157

10

The -E printer option used with lpadmin should do that.

lpadmin [-U username ] [ -h server[:port] ] -p printer option(s)

As pointed out in a comment below, make sure you add the -E after the printer name, because it is a printer option here, not a lpadmin option. Note the following excerpt from the man lpadmin page:

When specified before the -d, -p, or -x options, the -E option forces encryption when connecting to the server.

If the issue is recurrent you can probably create a CRON job with the lpadmin command. Hourly cron entry:

0 * * * * /usr/sbin/lpadmin -p your_printer -E

You can add that by running:

sudo crontab -e

Paused until further notice.

Posted 2010-03-03T13:25:43.687

Reputation: 86 075

This is the only solution that works for me. cups keeps pausing the printer for no reason pretty often. The error-policy doesn't fix anything. cupsenable doesn't fix anything. Only lpadmin does for me. – λuser – 2018-06-02T07:54:35.090

Be sure to use -p printer and not -d printer (which doesn't accept printer options, since it only sets printer as the default one). – Skippy le Grand Gourou – 2020-02-06T14:41:07.793

3

This is wrong. -E in this context is a printer option, and must go AFTER the printer name, otherwise you are just turning on communication encryption. https://developer.apple.com/library/mac/documentation/Darwin/Reference/Manpages/man8/lpadmin.8.html -- When specified before the -d, -p, or -x options, the -E option forces encryption when connecting to the server.

– scragar – 2014-04-28T17:23:02.907

6

My printer is HP CP1215 had also an error: Printer Paused - "/usr/lib/cups/backend/hp failed"

After restarting both cups and avahi-daemon and identifying printer with lpstat -p and enabling with cupsenable, I was able to print again. Restarting only cups and enabling did not do the trick.

I also changed default policy to retry-job and finally ended up avoiding errors in future with cronjob:

* * * * * lpstat -p |grep "poissa käytöstä" && service avahi-daemon restart; service cups restart; cupsenable HP_Tuloostin

where poissa käytöstä is Finnish localization text for maintenance "out of order" and HP_Tuloostin is name of my printer.

In my experience both default-policy and current printer policies should be configured to be retry-job. Default policy is just policy which you get when you are installing a new printer.

Janne Raatikainen

Posted 2010-03-03T13:25:43.687

Reputation: 61

2

ls /etc/cups/ppd/ |cut -d "." -f1 |grep -v VMware |xargs -i cupsenable {}

This lists all ppd files which represent an installed printer, cuts off the ppd extension, ignores a VMware ppd included on a lot of VMware servers (if you don't need this just remove |grep -v VMware), and passes the other names to xargs which unpauses all of the printers.

A cron job should make this work well.

Dana M

Posted 2010-03-03T13:25:43.687

Reputation: 21

1

If the problem is down to the fact that the GUI requires a login to resume the printer then another solution is to allow printer resume via the GUI without a login. To do so shutdown cups and edit this line sudo vi /etc/cups/cupsd.conf:

<Limit Pause-Printer Resume-Printer Enable-Printer Disable-Printer Pause-Printer-After-Current-Job Hold-New-Jobs Release-Held-New-Jobs Deactivate-Printer Activate-Printer Restart-Printer Shutdown-Printer Startup-Printer Promote-Job Schedule-Job-After Cancel-  Jobs CUPS-Accept-Jobs CUPS-Reject-Jobs>

And remove the Resume-Printer directive, then restart cups. If the directive appears on more than one <Limit> section then you can removal it from the relevant <Policy> section or remove from all. You should now be able to resume the printer without a login from the GUI. I saw this on macworld but it applies to any cups install.

Pierz

Posted 2010-03-03T13:25:43.687

Reputation: 880

1

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.

xaphod

Posted 2010-03-03T13:25:43.687

Reputation: 151

0

A bunch of the solutions here didn't work for me, (e.g. sudo cupsenable and lpadmin -E).

If you're using Debian 8.6, Cinnamon 2.2.16 (Linux) do this from your GUI start menu:

Click Administration | Print Settings,
Then select your stalled CUPS printer,
Click Unlock (and give it your admin password),
Click Server | Settings,
In this click the blue "Problems?" link. 

For Ubuntu 16.04:

Click System Settings | Printers,
Then Server | Settings,
Click the blue "Problems?" link. 

This opens the printing troubleshooter. It will tell you what to do next.

Probably you will just have to check the Enabled property for your CUPS printer in your Print Settings. (You will need to unlock first).

Finally, to avoid this from happening again, change the printers "policy" to "retry-job" in the printer setup mentioned above (under properties | policies).

Fixed it for me!

What causes this problem: If my wifi printer is powered down when I print to a CUPS PRINTER, and my policy is "stop printer", then I get a message that I couldn't print and the printer is disabled (Enabled is unchecked). Only if the policy is set to "retry job" will Enabled not be unchecked. A few minutes after the printer is powered back up your jobs will begin to print.

(My other post about this.)

Elliptical view

Posted 2010-03-03T13:25:43.687

Reputation: 864

0

Had to deal with the same CUPS nonsense here... Solution for me was a systemd script that runs every n minutes.

/usr/local/cups/enable_cups_printers.sh

#!/bin/sh
for printer in $(lpstat -v | perl -pe 's/device for ([A-Za-z0-9_]+):.*/\1/g')
do
    echo "Forcely enabling printer: $printer"
    # Enable:-E PrinterId:-p
    /usr/bin/lpadmin -E -p "$printer"
done

cups.enable.printers.service

[Unit]
Description = Forcely enable printer occassionally. Why CUPS disables printers in the first place has yet to be determined.

[Service]
Type = simple
ExecStart = /usr/local/cups/enable_cups_printers.sh

[Install]
WantedBy = multi-user.wants

cups.enable.printers.timer

[Unit]
Description=Run enable printers frequently to ensure connection difficulties are remedied.

[Timer]
OnBootSec=15min
OnUnitActiveSec=300

[Install]
WantedBy = timers.target

Jonathan Komar

Posted 2010-03-03T13:25:43.687

Reputation: 293

0

I updated cupsd.conf with the line:

ErrorPolicy abort-job

Then I restarted cupsd using: /etc/init.d/cups restart

But when I look at the printers.conf file, the ErrorPolicy is not updated. According to the cups documentation, line "ErrorPolicy abort-job" must appear in the printer section.

I also tried with lpadmin to update the ErrorPolicy. Nothing changes the ErrorPolicy or it does not make it to the printers.conf file.

What am I missing? How do I make sure that cupsd actually aborts a job on error?

kk1

Posted 2010-03-03T13:25:43.687

Reputation:

edit printers.conf – KawaiKx – 2014-06-29T04:19:54.463

0

lpadmin -p p-go-avtom2 -v p-go-avtom2 -E

Source

vserg

Posted 2010-03-03T13:25:43.687

Reputation: 1

6Care to explain what this does, exactly? Please add a little more context. – slhck – 2012-07-15T21:50:20.323

-1

As others have already said, 'cupsenable' or 'lpadmin -E' should do the trick.

A related issue is IIRC that by default CUPS configures the printer such that if printing a job fails somehow, the printer is disabled. You can change this to abort the job instead.

janneb

Posted 2010-03-03T13:25:43.687

Reputation: 987

-1 as -E is for encryption. – Elliptical view – 2016-10-09T01:09:34.673

See how to properly use -E as a printer option, not as a lpadmin option, in another answer above. – Elliptical view – 2016-10-11T16:43:08.540