View previous topic :: View next topic |
Author |
Message |
gentsquash l33t
Joined: 03 Nov 2004 Posts: 753 Location: Still a Gentoo beginner.
|
Posted: Fri May 26, 2006 8:19 pm Post subject: Auto-notification of USB-device (dis)connect |
|
|
Connecting or disconnecting a USB device causes a message
to appear in /var/log/messages.
Is there a simple way to have a pop-up appear, announcing the
(dis)connection? E.g, an call to the wall cmd or to usbview.
A somewhat clumsy solution is
Code: | watch --differences=cumulative 'tail /var/log/messages' |
I realize that there may exist complex notification
software for all kinds of events; I seek something just for
knowing if there is an electrical connection.
E.g, I shift some cables in order to catch my son's gerbil
that has just escaped, and without realizing it I
disconnect a USB device. _________________ Your thread resolved? Putting [SOLVED] in its title helps all Gentooers. (Button "edit" , first post)
Prof. Jonathan LF King, Mathematics dept., University of Florida |
|
Back to top |
|
|
Headrush Watchman
Joined: 06 Nov 2003 Posts: 5597 Location: Bizarro World
|
Posted: Sat May 27, 2006 1:10 am Post subject: |
|
|
Check out /etc/hotplug/usb.agent.
Depending on your exact need, you can easily modify the action for an add or a delete event to popup a message or whatever you want to happen.
Be careful in that when you update hotplug your changes will be replaced. (So make a backup.) |
|
Back to top |
|
|
gentsquash l33t
Joined: 03 Nov 2004 Posts: 753 Location: Still a Gentoo beginner.
|
Posted: Sun May 28, 2006 9:09 pm Post subject: |
|
|
Thank you, Headrush.
I read /etc/hotplug/usb.agent with interest, but I
understood little of it. With "usb.agent" as a keyword, a
websearch give this page,
http://lwn.net/Articles/123932/
which has
Code: | ... So, for example, if you want to be notified of all USB
hotplug events, put a symlink to your program in the
/etc/hotplug.d/usb/ directory that ends in .hotplug . A
typical /etc/hotplug.d tree one of my Gentoo-based systems
looks like the following:
/etc/hotplug.d/
`-- default
|-- 10-udev.hotplug -> ../../../sbin/udevsend
|-- 20-hal.hotplug -> /usr/libexec/hal.hotplug
`-- default.hotplug
This arrangement means that udevsend is called first for
any hotplug event, followed by HAL, and then finally, the
default linux-hotplug scripts. ...
|
As an experiment, I created a directory "usb" in
/etc/hotplug.d/ into which I placed a symlink
Code: | /etc/hotplug.d/usb:
17-usbview.hotplug -> /usr/bin/usbview |
I then plugged-in and removed several usb devices, but
usbview did not pop up.
(I did not, however, restart the system; is there a usb
equivalent of the rehash cmd?)
Could some kind soul post an example of how a user defines
a usb-triggered action? _________________ Your thread resolved? Putting [SOLVED] in its title helps all Gentooers. (Button "edit" , first post)
Prof. Jonathan LF King, Mathematics dept., University of Florida |
|
Back to top |
|
|
Headrush Watchman
Joined: 06 Nov 2003 Posts: 5597 Location: Bizarro World
|
Posted: Sun May 28, 2006 9:36 pm Post subject: |
|
|
Does usbview use the X server?
Remember, this is run as root, and by default in Gentoo root doesn't have X permissions.
Just test by dumping a message into the main log file. eg [b/]cat "See it works" >> /var/log/messages[/b]
Edit: I tested this and it works. |
|
Back to top |
|
|
gentsquash l33t
Joined: 03 Nov 2004 Posts: 753 Location: Still a Gentoo beginner.
|
Posted: Mon May 29, 2006 4:24 am Post subject: |
|
|
Headrush wrote: | Does usbview use the X server?
Remember, this is run as root, and by default in Gentoo
root doesn't have X permissions. |
A very good point. Following your lead, I put a script in
/etc/hotplug.d/usb/ that calls wall --and it worked. But...
Curiouser and curiouser, as Alice in Linuxland said. From the
cmd-line in a root shell I can run usbview, or as a subshell
and the usbview window appears. I did indeed check, in this
root shell, that $HOME points to the home dir of my user, not
that of root, and that ~root/.Xauthority has no cookie (it
exists, but is empty).
However, if I put usbview in the above script, and run it
from my root or my user's shell, no usbview-window
appears. Could this be related to the distinction between
interactive and non-interactive shells? _________________ Your thread resolved? Putting [SOLVED] in its title helps all Gentooers. (Button "edit" , first post)
Prof. Jonathan LF King, Mathematics dept., University of Florida |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|