I want to execute my script when adding / removing of hardware is detected.
Now I use a loop and sleep every 10 sec, to recheck a new hardware, but I thought it would be better if I could put my script to system path that will run every time that hardware changes are detected, similar to "run every log in" when put script path to /etc/rc.local
.
Write a udev rule that executes the script each time the appropriate hardware is added or removed.
Running external programs upon certain events
Yet another reason for writing udev rules is to run a particular program when a device is connected or disconnected. For example, you might want to execute a script to automatically download all of your photos from your digital camera when it is connected.