Running a shell script on device mount

Something I have always wondered but never had any luck finding information on is running a shell script when a device mounts...

Lets say I have an external hard drive as a back up, every time I plug the device in I want to launch a shell script to rsync a few directories.

How would I do this other then polling the mount points?

Thanks

What OS ?

On recent Linux, you can have a script run when the device is detected. (not when it mounts, but when it is detected) by crafting a udev rule for that device.

udev rule... i will check this out. FreeBSD.

For FreeBSD see /etc/rc.d/devd and devd.conf and devd
and FreeNAS forum � View topic - USB attach, auto-mount, rsync, detach & umount(auto-backup)