You can make a rules file in /etc/udev/rules.d/
folder and make it run a bash script when your USB device is connected. For this you need to find the ID_Vendor and ID_Product code of device. Run lsusb
command. There you will see something like Bus 003 Device 005: ID ffff:0005.
In this case idVendor = ffff
and idProduct = 0005
. Yours will be different.
Than create for example 50-myUSB.rules
file in the above directory with content something like (change ID_vendor and ID_product):
ATTRS{idVendor}=="ffff", ATTRS{idProduct}=="0005", RUN+="/path/to/script.sh"
This will run script.sh
every time you will plug in the device. Now you have to create the script.sh
with content something like:
#! /bin/bash
service network-manager restart
(Somebody can propose better script.)
Now you have to give it execution permitions:
chmod +x script.sh
I am not sure if you need to restart the OS or not for the changes to take effect.
Click here if you want to know more about udev rules.