#!/bin/bash ## Version 0.1 200311 initial version ## Version 0.2 20040225: find unmounted devices (instead of hardcoded) ## this script finds partitions of types defined in ${FILESYSTEMS} ## on local accessible mass storage medias, where no partition ## is mounted yet. ## So if your device got more than one parition and one of them is ## already mounted, this script ignores this device (in order to find ## NEW usb-sticks plugged into the system). # where should I mount the USB-stick: MOUNTPOINT="/mnt/usbstick" # options for 'mount'; separated using commatas (see 'man mount') MOUNTOPTIONS="uid=1000,gid=1000" # get device other than /dev/scd0: UNMOUNTEDDEVICES=`/usr/sbin/scsiinfo -l|/bin/sed 's/\/dev\/scd0//'` # try to mount using this filesystems: FILESYSTEMS="vfat msdos" do_mount() { #echo "DEBUG: trying to mount [$CURRENTDEVICE] on [$MOUNTPOINT] using fs-type [$CURRENTFS]" /bin/mount -o "$MOUNTOPTIONS" -t "$CURRENTFS" "$CURRENTDEVICE" "$MOUNTPOINT" 2>/dev/null } handle_mount_success_and_exit() { echo "success while mounting [$CURRENTDEVICE] on [$MOUNTPOINT] using fs-type [$CURRENTFS]" exit } handle_mount_failure() { echo "ERROR: could not mount [$DEVICE] on [$MOUNTPOINT]. Tried to use filesystems [$FILESYSTEMS]." exit } handle_no_device_found() { echo "WARNING: handle_no_device_found called; falling back to \"/dev/sda\"" DEVICE=/dev/sda } loop_mounting() { for CURRENTFS in $FILESYSTEMS ; do do_mount "$CURRENTDEVICE" "$CURRENTFS" && handle_mount_success_and_exit "$CURRENTDEVICE" "$CURRENTFS" done } loop_devices() { for CURRENTMAINDEVICE in $UNMOUNTEDDEVICES ; do #echo "DEBUG: DEVICE: ["$CURRENTMAINDEVICE"]" CURRENTDEVICE="$CURRENTMAINDEVICE" loop_mounting CURRENTDEVICE="$CURRENTMAINDEVICE"1 loop_mounting CURRENTDEVICE="$CURRENTMAINDEVICE"0 loop_mounting CURRENTDEVICE="$CURRENTMAINDEVICE"2 loop_mounting done } ######################################################## TEMP1="TEMPmounteddevices.txt" TEMP2="TEMPalldevices.txt" ## FIXXME: besser: cat /proc/mounts mount|awk ' /^\/dev/ {print substr($1,1,8)}'|sort|tr " " "\n" >${TEMP1} /usr/sbin/scsiinfo -l|sort|tr " " "\n" >${TEMP2} ## FIXXME: besser: mit comm (siehe Posting) UNMOUNTEDDEVICES=`diff ${TEMP1} ${TEMP2}|egrep "^>"|sed 's#> ##'|tr '\n' " "` rm ${TEMP1} ${TEMP2} /sbin/modprobe usb-storage [ -z "$UNMOUNTEDDEVICES" ] && handle_no_device_found loop_devices handle_mount_failure /sbin/rmmod usb-storage /sbin/rmmod msdos #end