Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

1 Answer 1

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.

See:

share|improve this answer

Your Answer

 
discard

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.