Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want a bash script to monitor USB ports of a linux server to detect when an external hard drive is plugged in and removed.

When a USB external drive is plugged in or removed, a text file is generated in some temp file about usb drive specs and time.

share|improve this question
up vote 2 down vote accepted

You probably already have udev running on your system, and it is monitoring connect/disconnect events. With the proper configuration it can trigger scripts to run, but it is primarily designed to create the device nodes.

On a Debian/Ubuntu system take a look at the existing rules in /lib/udev/rules.d, and /etc/udev/rules.d`. See the Run section of the udev man page, for details about executing a task.


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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