Automatic script

Hi,
is it possible to automatically run a script (bash) when an event occurs?
I mean, let's say that I (or one of my users) plug in a flash memory (USB) ... is it possible to run a script every time I do this action (let's say to log user, date and other infos on a file)?

Thanks!

Bye...

It depends on your USB subsystem. Many of them are eminently scriptable and work exactly as you describe. Look at hotplug and hal for a start if you are on Linux. If you examine your system log when you insert a removable storage device, you should get some hints about where to look, as well.

("User" is not well defined in this context, by the by; the insertion of a USB stick is not necessarily performed by a user who exists on the system, much less one who is logged in; of course, if only one user is logged in, you can make some conjectures, but that's heuristics.)

You can write a cronjob that is started every minute and checks for a new usb device like "lsusb" on Linux and if their is an additional device it will collect your data and copy it on the usb stick.
To have the time between the minute checked too, you can call this test in a while loop every 2 seconds and count up to 29 for example. Place a file under /tmp as lock maybe, so your script knows, that a copy is in progress. When the device is removed, the check for usb devices should remove that lockfile too.

Unfortunately I'm not under Linux! I'm using Mac OS X but I'm a newbie so ... I think it's in the UNIX side!

Bye...

Hi zaxxon,
I had the same initial idea! But I would like to avoid continuous submissions! I think that the OS already does it (when I plug the flash it's immediately mounted) so it would be better to append to it!

Bye...

Yes, but some mechanism has to do your copy jobs and I doubt, that the same part that realizes that there is a new usb device can do any actions like copy stuff for you etc. on it's own by passing that as parameter or in some config file.
But I have no clue about Mac OS X either.