command line - Running the script when it detects I/O - Ask Ubuntu
i have bluetooth mouse xinput setting script run whenever have connect mouse. i'm alias short key 'bm' bash file execution want know if there automatic way execute bash file or alias command whenever detects mouse connection.
thank in advance!
ubuntu 16.10
i use .rules file.
first, find out id_vendor_id
, id_model_id
of mouse. disconnect mouse, run command , connect mouse (the |grep id
part filter information don't need).
udevadm monitor --property|grep id
lets these values:
id_vendor_id=0a12 id_model_id=0001
now create file in rules folder (96 priority of rule):
sudo gedit /etc/udev/rules.d/96-myusb.rules
add these 2 lines using values id_vendor_id
, id_model_id
. if don't want when remove it, don't include second line.
action=="add", subsystem=="usb",env{id_vendor_id}=="0a12", env{id_model_id}=="0001",run+="/usr/local/bin/myusb-add.sh" action=="remove", subsystem=="usb",env{id_vendor_id}=="0a12",env{id_model_id}=="0001",run+="/usr/local/bin/myusb-remove.sh"
you can test works creating 2 scripts:
$ sudo gedit /usr/local/bin/myusb-add.sh
add (change add
remove
in other one):
#!/bin/bash echo "added" >> /tmp/myusb.log
finally, tail file tail -f /tmp/myusb.log
, connect/disconnect mouse. should see text gets added file.
Comments
Post a Comment