LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 09-16-2020, 08:42 AM   #1
ajkrishock
Member
 
Registered: Jul 2003
Distribution: Linux Mint
Posts: 33

Rep: Reputation: 15
USB device ports


All,

This is hopefully an easy question..

I would like to have my Linux notebook report back to me the port name after I insert a USB connector.

For example, I insert a USB-to-Serial adapter device and linux throws up a message saying "USB device detected on port /dev/ttyUSB0"

Is this possible?
 
Old 09-16-2020, 01:43 PM   #2
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,281

Rep: Reputation: 320Reputation: 320Reputation: 320Reputation: 320
Of course it is possible. You can add udev rule to run specific program on device connection. Add file /etc/udev/rules.d/99-USB.rules with content:
Code:
ACTION=="add", SUBSYSTEMS=="usb", ENV{DEVNAME}=="/dev/*", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/YOUR_USERNAME/.Xauthority", ENV{DBUS_SESSION_BUS_ADDRESS}="unix:path=/run/user/YOUR_USERID/bus", RUN+="/usr/bin/sudo -u YOUR_USERNAME --preserve-env=DISPLAY,XAUTHORITY,DBUS_SESSION_BUS_ADDRESS   /usr/bin/notify-send 'USB device detected on port $env{DEVNAME}'"
Change YOUR_USERNAME to your real username and YOUR_USERID into your real user id (you can get it by command "id"). If you need automatic detection which user account is currently logged in GUI you would need more sophisticated approach.

You can specify more or less matches in rule depending on used devices, for only USB to serial converters add SUBSYSTEM=='tty', look in "man 7 udev" for more info. And for "notify-send" you need to install "libnotify-bin" package. You can for example change icon for message and time to display.

Last edited by eSelix; 09-17-2020 at 07:46 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
USB 2.0 ports won't work on my Gigabyte GA-970A-DS3P FX motherboard. USB 3.0 ports work great. myusb2.0portswon'twork Linux - Hardware 1 03-25-2019 03:23 AM
LXer: USB 2.0, USB 3.0 And USB Type C – USB Ports Explained LXer Syndicated Linux News 0 11-29-2017 03:40 PM
USB 2.0 ports: devices not detected, but works fine with USB 1.1 ports (Kubuntu 6.06) KWTm Linux - Hardware 1 05-09-2007 04:42 AM
ports, ports, ports cjae Linux - Networking 1 04-09-2006 09:38 AM
HP Deskjet (USB) & CUPS & Slackware 9.1: Unable to open USB device "usb:/dev/usb/lp0&qu arnostienen Slackware 2 01-29-2004 03:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 09:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration