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
enableprinter when plugged in - Automatically
disableprinter 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 #
lsusbExample 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 -dExample output:
printer Canon_iP2700_series disabled. Printer offlineNote 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-installer2. Run Installer #
sudo chmod +x install.sh
sudo ./install.shThe 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.confFormat:
# Format: VendorID:ProductID Printer_Name
04a9:10d3 Canon_iP2700_series
1a2b:3c4d Epson_L3150_seriesAdd all your printers here. One printer per line.
Step 3: Verify & Monitor #
Check Printer Status #
lpstat -p -dView Live Log #
tail -f /opt/printer-monitor/logs/monitor.logTest: 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 - EnabledAdding a New Printer #
Got a new printer? Simple:
- Check
lsusbandlpstat -pfor new printer’s ID and name - Edit
/opt/printer-monitor/src/printers.conf, add new line - 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.serviceRun Uninstaller #
cd printer-monitor-installer
sudo chmod +x uninstall.sh
sudo ./uninstall.shOr manually:
sudo rm -rf /opt/printer-monitor
sudo rm /etc/systemd/system/printer-monitor.service
sudo systemctl daemon-reloadTroubleshooting #
Q: Printer not detected?
- Verify VendorID:ProductID with
lsusb(must match config) - Ensure printer name in
lpstat -pmatches 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
cupsenablemanually
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.rulesAdd:
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! 🖨️✨