1

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.

Kashif
  • 493
  • 9
  • 20

1 Answers1

2

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:

Zoredache
  • 130,897
  • 41
  • 276
  • 420