You are not logged in.

#1 2008-01-26 16:20:08

leo2501
Member
From: Buenos Aires, Argentina
Registered: 2007-07-07
Posts: 658

USB mounter & umounter script

HI! my girlfriend uses my computer, so i make this little script for her, hope you found it useful, and comment anything about it smile

#!/bin/bash
#Mount & umount usb devices
echo 'Select device to mount (full path):'
echo '/dev/sdx'
echo '/dev/sdx1'
ls -l /dev/sd*
read device
echo Select the mount point:
echo 1. /mnt/usb
echo 2. /mnt/usb2
echo 3. /mnt/usb3
echo 4. /mnt/usb4
read point
while [ "$point" != "1" ] && [ "$point" != "2" ] && [ "$point" != "3" ] && [ "$point" != "4" ]; do
    echo invalid option
    echo Select a valid mount point
    read point
done
case $point in
1) sudo mount -t vfat $device /mnt/usb && echo $device mounted to /mnt/usb && echo --- Press a key to umount --- && read && sudo umount /mnt/usb && echo /mnt/usb umounted && read;;
2) sudo mount -t vfat $device /mnt/usb2 && echo $device mounted to /mnt/usb2 && echo --- Press a key to umount --- && read && sudo umount /mnt/usb2 && echo /mnt/usb2 umounted && read;;
3) sudo mount -t vfat $device /mnt/usb3 && echo $device mounted to /mnt/usb3 && echo --- Press a key to umount --- && read && sudo umount /mnt/usb3 && echo /mnt/usb3 umounted && read;;
4) sudo mount -t vfat $device /mnt/usb4 && echo $device mounted to /mnt/usb4 && echo --- Press a key to umount --- && read && sudo umount /mnt/usb4 && echo /mnt/usb4 umounted && read;;
esac

Last edited by leo2501 (2008-10-27 10:10:31)


Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery

Offline

#2 2008-10-27 09:17:12

magarcan
Member
Registered: 2008-10-23
Posts: 19

Re: USB mounter & umounter script

This doesn't work for me, after choose mi dispositive script shows me mount help. Any idea??? Thanks

Offline

#3 2008-10-27 10:17:40

leo2501
Member
From: Buenos Aires, Argentina
Registered: 2007-07-07
Posts: 658

Re: USB mounter & umounter script

i modify it, it was the "ls -l /dev/sd* | grep storage" (line 6), i think that this changed with a kernel update

Thankyou!


Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery

Offline

#4 2008-10-27 11:24:05

klixon
Member
From: Nederland
Registered: 2007-01-17
Posts: 525

Re: USB mounter & umounter script

Editted for readability and some basic error-checking:
Problem is, i have no way to test it right now, so let me know if you try it and run into problems cool

#!/bin/bash
#Mount & umount usb devices
echo Select device to mount:
select device in $( ls -l /dev/sd[a-z]*[0-9]* | awk '/storage/ {print $9}' ); do
  if [ -z $device ]; then 
    echo Invalid option 
    continue
  fi
  echo You selected \"$device\"
  break
done

echo Select the mount point:
select point in /mnt/usb{,{1..4}}; do
  if [ -z $point ]; then
    echo Invalid option
    continue
  fi
  echo You selected \"$point\"
  if [ grep ${point} /proc/mounts ]; then
    echo \"$point\" is already in use. Select another mount point.
    continue
  fi
  break
done

sudo mount -t vfat $device $point 
while [ $? -gt 0 ]; do
  echo An error occured while trying to mount $device.
  echo -n Try mounting with another filesystem choice? [Y/n] 
  read 
  case ${REPLY:-y} in
      y|Y) echo -n Enter a filesystem, or leave blank to let mount decide: ;;
      *)   echo Exiting && exit 1 ;;
  esac
  read
  fs="${REPLY:+-t ${REPLY}}"
  sudo mount $fs $device $point
done
      
echo $device mounted to $point 
echo --- Press a key to umount --- 
read

sudo umount $point 
if [ $? -gt 0 ]; then
  echo An error occured while trying to umount $device.
  read
  exit 1
else
  echo $point umounted
  read
fi

Stand back, intruder, or i'll blast you out of space! I am Klixon and I don't want any dealings with you human lifeforms. I'm a cyborg!

Offline

Board footer

Powered by FluxBB