Running ones notebook on a docking station is quite comfortable until you want to undock it. To ensure that no data will be corrupted, you have to unmount all file systems attached via the docking stations ports (USB, FireWire etc.).
This script was written for the ThinkPad T400 and the ThinkPad advanced mini dock. In theory it should work with any other setup as well.
Follow the instructions on top of the script to set it up properly. Be aware, that you have to provide a regular expression for syspath_usb_at_docking (in most cases, just add ".*" at the end of the string).