Tried my best to stay posix with this, note that it will fail if you do not have a suitable "udevadm" package available for displaying udev info.
#!/bin/bash
command_exists () {
type "$1" &> /dev/null
}
CMD=""
if command_exists udevadm; then
CMD="$(which udevadm) info -q all -n"
fi
if command_exists udevinfo; then
CMD="$(which udevinfo) -q all -n"
fi
echo "The udevinfo command for this system is $CMD"
for disk in /dev/sd*
do
DISK=$($CMD $disk | grep ID_BUS)
if [[ "$DISK" == *usb ]]; then
echo "$disk is USB, now unmounting.."
umount $disk
fi
done