1

I want to write a simple script that will send email to a specific address as soon as a USB device is plugged into a system or unplugged. Would someone please provide me a code snippet for this? I want to run it on different flavors of Linux where Ruby will be installed already.

4

1 回答 1

2

You could add a new udev rule as follows. Create a file /etc/udev/rules.d/99-my-custom-rule, whose contents looks as follows:

SUBSYSTEM=="usb", ACTION=="add", RUN+="usb_notify_admin add %b"
SUBSYSTEM=="usb", ACTION=="remove", RUN+="usb_notify_admin remove %b"

Then put a script usb_notify_admin somewhere in the PATH:

#!/bin/sh
echo $@ | mail -s "USB Notify Script" admin@example.com

Details:

于 2012-04-16T11:01:19.340 回答