Thanks for replying shep.
I've tried adding dbus-launch to my script, but unfortunately to no avail. It's a headless machine and hp-levels appears to cope with that when it's run by my normal user.
Full output from both users with and without dbus:
www-data without dbus-launch:
Code: Select all
HP Linux Imaging and Printing System (ver. 3.14.6)
Supply Levels Utility ver. 2.0
Copyright (c) 2001-13 Hewlett-Packard Development Company, LP
This software comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to distribute it
under certain conditions. See COPYING file for more details.
hp-levels[18915]: debug: getDeviceUri(None, None, ('hp',), None, , True)
hp-levels[18915]: debug: Mode=0
hp-levels[18915]: debug: Cache miss: deskjet_d2400_series
hp-levels[18915]: debug: Reading file: /usr/share/hplip/data/models/models.dat
hp-levels[18915]: debug: Searching for section [deskjet_d2400_series] in file /usr/share/hplip/data/models/models.dat
hp-levels[18915]: debug: Found section [deskjet_d2400_series] in file /usr/share/hplip/data/models/models.dat
hp-levels[18915]: debug: {'hp:/usb/Deskjet_D2400_series?serial=TH779324RN04Y7': ['Deskjet']}
Using device: hp:/usb/Deskjet_D2400_series?serial=TH779324RN04Y7
error: Unable to connect to dbus session bus. org.freedesktop.DBus.Error.NotSupported: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
error: Unable to communicate with device (code=12): hp:/usb/Deskjet_D2400_series?serial=TH779324RN04Y7
hp-levels[18915]: debug: Exception: 2 (Device not found)
error: Error opening device (Device not found). Exiting.
Normal user without dbus-launch:
Code: Select all
HP Linux Imaging and Printing System (ver. 3.14.6)
Supply Levels Utility ver. 2.0
Copyright (c) 2001-13 Hewlett-Packard Development Company, LP
This software comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to distribute it
under certain conditions. See COPYING file for more details.
hp-levels[18907]: debug: getDeviceUri(None, None, ('hp',), None, , True)
hp-levels[18907]: debug: Mode=0
hp-levels[18907]: debug: Cache miss: deskjet_d2400_series
hp-levels[18907]: debug: Reading file: /usr/share/hplip/data/models/models.dat
hp-levels[18907]: debug: Searching for section [deskjet_d2400_series] in file /usr/share/hplip/data/models/models.dat
hp-levels[18907]: debug: Found section [deskjet_d2400_series] in file /usr/share/hplip/data/models/models.dat
hp-levels[18907]: debug: {'hp:/usb/Deskjet_D2400_series?serial=TH779324RN04Y7': ['Deskjet']}
Using device: hp:/usb/Deskjet_D2400_series?serial=TH779324RN04Y7
error: Unable to connect to dbus session bus. org.freedesktop.DBus.Error.NotSupported: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
hp-levels[18907]: debug: num_pens = 2
hp-levels[18907]: debug: pen 0 {'index': 0, 'kind': 3L, 'level': 79, 'ack': False, 'hp-ink': False, 'dvc': 0L, 'level-trigger': 0, 'virgin': False, 'health': 0, 'known': False, 'type': 1, 'id': 9}
hp-levels[18907]: debug: pen 1 {'index': 1, 'kind': 3L, 'level': 64, 'ack': False, 'hp-ink': False, 'dvc': 0L, 'level-trigger': 0, 'virgin': False, 'health': 0, 'known': False, 'type': 2, 'id': 10}
hp-levels[18907]: debug: 1: agent_type 1 agent_kind 3 agent_sku '21(C9153A/G)'
hp-levels[18907]: debug: 2: agent_type 2 agent_kind 3 agent_sku '22(C9352A/G)'
Black cartridge
Part No.: 21(C9153A/G)
Health: Good/OK
----------------------------------------------------------------
|////////////////////////////////////////////////// | (approx. 79%)
----------------------------------------------------------------
Tri-color cartridge
Part No.: 22(C9352A/G)
Health: Good/OK
----------------------------------------------------------------
|//////////////////////////////////////// | (approx. 64%)
----------------------------------------------------------------
Done.
Adding the following to the script:
if test -z "$DBUS_SESSION_BUS_ADDRESS" ; then
## if not found, launch a new one
eval `dbus-launch --sh-syntax --exit-with-session`
echo "D-Bus per-session daemon address is: $DBUS_SESSION_BUS_ADDRESS"
fi
www-data with dbus-launch:
Code: Select all
HP Linux Imaging and Printing System (ver. 3.14.6)
Supply Levels Utility ver. 2.0
Copyright (c) 2001-13 Hewlett-Packard Development Company, LP
This software comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to distribute it
under certain conditions. See COPYING file for more details.
hp-levels[18946]: debug: getDeviceUri(None, None, ('hp',), None, , True)
hp-levels[18946]: debug: Mode=0
hp-levels[18946]: debug: Cache miss: deskjet_d2400_series
hp-levels[18946]: debug: Reading file: /usr/share/hplip/data/models/models.dat
hp-levels[18946]: debug: Searching for section [deskjet_d2400_series] in file /usr/share/hplip/data/models/models.dat
hp-levels[18946]: debug: Found section [deskjet_d2400_series] in file /usr/share/hplip/data/models/models.dat
hp-levels[18946]: debug: {'hp:/usb/Deskjet_D2400_series?serial=TH779324RN04Y7': ['Deskjet']}
Using device: hp:/usb/Deskjet_D2400_series?serial=TH779324RN04Y7
error: Unable to connect to dbus session bus. org.freedesktop.DBus.Error.NoServer: Failed to connect to socket /tmp/dbus-BC4B9KRy7Q: Connection refused
error: Unable to communicate with device (code=12): hp:/usb/Deskjet_D2400_series?serial=TH779324RN04Y7
hp-levels[18946]: debug: Exception: 2 (Device not found)
error: Error opening device (Device not found). Exiting.
Normal user with dbus-launch:
Code: Select all
HP Linux Imaging and Printing System (ver. 3.14.6)
Supply Levels Utility ver. 2.0
Copyright (c) 2001-13 Hewlett-Packard Development Company, LP
This software comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to distribute it
under certain conditions. See COPYING file for more details.
hp-levels[18932]: debug: getDeviceUri(None, None, ('hp',), None, , True)
hp-levels[18932]: debug: Mode=0
hp-levels[18932]: debug: Cache miss: deskjet_d2400_series
hp-levels[18932]: debug: Reading file: /usr/share/hplip/data/models/models.dat
hp-levels[18932]: debug: Searching for section [deskjet_d2400_series] in file /usr/share/hplip/data/models/models.dat
hp-levels[18932]: debug: Found section [deskjet_d2400_series] in file /usr/share/hplip/data/models/models.dat
hp-levels[18932]: debug: {'hp:/usb/Deskjet_D2400_series?serial=TH779324RN04Y7': ['Deskjet']}
Using device: hp:/usb/Deskjet_D2400_series?serial=TH779324RN04Y7
HP Linux Imaging and Printing System (ver. 3.14.6)
System Tray Status Service ver. 2.0
Copyright (c) 2001-13 Hewlett-Packard Development Company, LP
This software comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to distribute it
under certain conditions. See COPYING file for more details.
warning: No display found.
error: hp-systray requires Qt4 GUI and DBus support. Exiting.
warning: Unable to connect to dbus. Is hp-systray running?
hp-levels[18932]: debug: num_pens = 2
hp-levels[18932]: debug: pen 0 {'index': 0, 'kind': 3L, 'level': 79, 'ack': False, 'hp-ink': False, 'dvc': 0L, 'level-trigger': 0, 'virgin': False, 'health': 0, 'known': False, 'type': 1, 'id': 9}
hp-levels[18932]: debug: pen 1 {'index': 1, 'kind': 3L, 'level': 64, 'ack': False, 'hp-ink': False, 'dvc': 0L, 'level-trigger': 0, 'virgin': False, 'health': 0, 'known': False, 'type': 2, 'id': 10}
hp-levels[18932]: debug: 1: agent_type 1 agent_kind 3 agent_sku '21(C9153A/G)'
hp-levels[18932]: debug: 2: agent_type 2 agent_kind 3 agent_sku '22(C9352A/G)'
Black cartridge
Part No.: 21(C9153A/G)
Health: Good/OK
----------------------------------------------------------------
|////////////////////////////////////////////////// | (approx. 79%)
----------------------------------------------------------------
Tri-color cartridge
Part No.: 22(C9352A/G)
Health: Good/OK
----------------------------------------------------------------
|//////////////////////////////////////// | (approx. 64%)
----------------------------------------------------------------
Done.