Skip to main content
Auto Enable/Disable USB Printer via CUPS & UDEV

Auto Enable/Disable USB Printer via CUPS & UDEV

Zarvelion Zynji
Author
Zarvelion Zynji
Tech enthusiasts (self-proclaimed). Gaming addict (diagnosed). Anime simp (no regrets). I turn my hyperfixations into content—welcome to the chaos.
Table of Contents

Problem: Printer Stuck in Idle Status
#

When using CUPS, USB printers often get stuck in idle status even after disconnection (power off or USB unplugged). The status doesn’t automatically change to disabled. This gets tedious when managing multiple printers.

This guide covers:

  • Automatically enable printer when plugged in
  • Automatically disable printer when unplugged + show “Printer offline” message
  • Support multiple printers simultaneously without script modifications

What are CUPS & UDEV?
#

CUPS (Common Unix Printing System) = standard Linux printing subsystem for managing printer status (enabled/disabled).

UDEV (Userspace /DEV) = kernel subsystem that detects hardware plug/unplug events in real-time.

Combined → automatically enable printer on plug, disable on unplug. More reliable and stable than manual polling.


Step 1: Get Printer Info
#

Get VendorID & ProductID
#

lsusb

Example output:

Bus 001 Device 003: ID 04a9:10d3 Canon, Inc. iP2700 series
  • 04a9 = VendorID
  • 10d3 = ProductID (remember these two)

Check Printer Name in CUPS
#

lpstat -p -d

Example output:

printer Canon_iP2700_series disabled.  Printer offline

Note this printer name as well — you’ll need it in the config.


Step 2: Install via Installer (Recommended) #

The easiest approach: download the pre-built installer, run the setup script, and you’re done. Files and service are neatly organized.

1. Download & Extract Installer
#

wget -O printer-monitor-installer.tar.gz "http://cdn.zynji.my.id/cscript/printer-monitor-installer.tar.gz"
tar -xvzf printer-monitor-installer.tar.gz
cd printer-monitor-installer

2. Run Installer
#

sudo chmod +x install.sh
sudo ./install.sh

The installer will:

  • Create /opt/printer-monitor/{bin,src,logs} directory structure
  • Deploy the monitoring script
  • Setup systemd service
  • Enable auto-start on boot

3. Edit Printer Config
#

sudo nano /opt/printer-monitor/src/printers.conf

Format:

# Format: VendorID:ProductID Printer_Name
04a9:10d3 Canon_iP2700_series
1a2b:3c4d Epson_L3150_series

Add all your printers here. One printer per line.


Step 3: Verify & Monitor
#

Check Printer Status
#

lpstat -p -d

View Live Log
#

tail -f /opt/printer-monitor/logs/monitor.log

Test: Unplug & Plug Printer
#

Watch the log while disconnecting the printer from USB. Within ~5 seconds, the status should change:

[timestamp] - Canon_iP2700_series disconnected - Disabled
[timestamp] - Canon_iP2700_series connected - Enabled

Adding a New Printer
#

Got a new printer? Simple:

  1. Check lsusb and lpstat -p for new printer’s ID and name
  2. Edit /opt/printer-monitor/src/printers.conf, add new line
  3. Save — the monitor script auto-detects within 5 seconds

No service restart needed.


Remove / Uninstall Monitor
#

Stop the Service
#

sudo systemctl stop printer-monitor.service
sudo systemctl disable printer-monitor.service

Run Uninstaller
#

cd printer-monitor-installer
sudo chmod +x uninstall.sh
sudo ./uninstall.sh

Or manually:

sudo rm -rf /opt/printer-monitor
sudo rm /etc/systemd/system/printer-monitor.service
sudo systemctl daemon-reload

Troubleshooting
#

Q: Printer not detected?

  • Verify VendorID:ProductID with lsusb (must match config)
  • Ensure printer name in lpstat -p matches your config exactly
  • Try restarting service: sudo systemctl restart printer-monitor.service

Q: Status not changing on plug/unplug?

  • Check logs: tail -f /opt/printer-monitor/logs/monitor.log
  • Verify service is running: sudo systemctl status printer-monitor.service
  • Ensure user has CUPS permissions: test cupsenable manually

Q: Many errors in log?

  • Verify printer ID: lsusb -d VendorID:ProductID (should show output)
  • Verify printer name in CUPS: lpstat -p | grep "printer_name"

Alternative: Manual UDEV Setup (Single Printer)
#

For single printer or manual setup, edit UDEV rules directly:

sudo nano /etc/udev/rules.d/99-usb-printer.rules

Add:

ACTION=="add", SUBSYSTEM=="usb", ENV{ID_VENDOR_ID}=="04a9", ENV{ID_MODEL_ID}=="10d3", \
    RUN+="/bin/sh -c '/usr/sbin/cupsenable Canon_iP2700_series && /usr/sbin/cupsaccept Canon_iP2700_series'"

ACTION=="remove", SUBSYSTEM=="usb", ENV{ID_VENDOR_ID}=="04a9", ENV{ID_MODEL_ID}=="10d3", \
    RUN+="/bin/sh -c '/usr/sbin/cupsdisable Canon_iP2700_series && /usr/sbin/cupsreject -r \"Printer offline\" Canon_iP2700_series'"

Reload UDEV:

sudo udevadm control --reload-rules
sudo udevadm trigger

💡 However, the installer approach is much more flexible and stable for multi-printer scenarios.


Summary
#

✔ Automatically enable/disable printer on plug/unplug
✔ Support multiple printers without script changes
✔ Convenient installer, ~2 minute setup
✔ Easy to manage and troubleshoot

Your printer system is now smart and automatic! 🖨️✨

Related


Load Comments