5

How can I find out when a device is connected to my FreeBSD machine? Lets say I plug in a USB device, HDMI device, Bluetooth or something like that.

Can I have a console output to say [device] and gives some output about the device?

5

All other answers are good, if you want only to check if a device is connected (checking kernel messages with dmesg, check in /var/log files and use some tools like usbconfig, pciconf or camcontrol).

But, if you want more (handle a message and execute a program or something like that when you plug your device), you can use devd.

When you connect a device, FreeBSD kernel will generate messages:

  • when you plug your device, an attach message is generated
  • when you unplug your device, a detach message is generated
  • and more (see devd.conf man page if you want more information).

FreeBSD uses devd by default, and its configuration is stored in /etc/devd/ and /etc/devd.conf. If you use linux, the same features exist with devfs and udev.

You can find some examples in /usr/share/examples/etc/devd.conf.

  • 1
    this was the best, setting up devd rules allowed me to just get console logs without constantly reading the logs; thanks. – user1610950 Sep 24 '16 at 6:32
2

dmesg | grep -i USB will give you the list of connected

To get information about USB devices. usbconfig can help give it a try.

or

pciconf -lv pciconf diagnostic utility for the PCI bus

  • I am not using Mac OS – user1610950 Sep 13 '16 at 13:12
  • @user1610950 But you are using UNIX, all those command work fine under unix. – GAD3R Sep 16 '16 at 9:13
1

You will always find info about new connected devices in dmesg and /var/log/messages.

For bluetooth you can check with: hcitool dev

For usb devices, try lsusb (-v).

Other useful commands: lshw (-short), hwinfo (--short) (if installed), lspci (-v), lsblk, df -h, fdisk -l, multipath -ll, mount, dmidecode, cat /proc/scsi/scsi, hdparm -i /dev/sda. There are multiple variations of these commands depending on your needs.

  • 1
    Is there a way to get console output without constantly rescanning the log messages? Isn't there some built in system so when a device is attached some type of notification is fired? I mean okay, how does the device get written to /var/log/messages. Can I intercept the call that writes the device to the log and just output it to the console instead? – user1610950 Sep 13 '16 at 7:36
  • 1
    You can use watch. For example: watch "grep usb /var/log/messages | tail -20" and watch "dmesg | grep usb | tail -15". Of course you can make a script to send an email for example when a change is detected (an usb is plugged/unplugged). See this thread for more info: unix.stackexchange.com/questions/116536/… – Futur'Fusionneur Sep 13 '16 at 8:01
  • @Futur'Fusionneur First you need to install usbutils to be allowed to use lsusb. – GAD3R Sep 16 '16 at 9:16
1

You can output the kernel log with dmesg. The full log is in /var/log/messages. There you will find information when new devices are detected or have disappeared, and log entries about some other actions.

If you want to integrate scripts or programs, you can take a look at /etc/devd.conf (man page). This is a text file containing rules with match expressions and actions. In this way you can load modules and execute binaries/scripts when devices are registered.

1

The lshal command will give you the DMI/SMBIOS hardware information (dmidecode under Linux)

You can list your connected USB device through:

camcontrol devlist 

Or :

usbconfig

To list pci devices:

pciconf -l

Also you can use the lsusb command under FreeBSD after Installing the usbutils package :

pkg install usbutils

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.