Udev in linux subsystem helps to write scripts to do a specific action when a new device is added or an existing device is removed from the system.
The following article helps you to write your own basic script by identifying a device and adding the specific udev rules. Refer An introduction to Udev: The Linux subsystem for managing device events for more details.