Advertisement
yokmp

Un-/Mount multible devices

Oct 11th, 2011
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.98 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4. # A simple u/mount devices script. Fast written for my
  5. # Backupserver. Shurely not the best one but it works (=
  6. #
  7. # If you got problems with this one, send me a PM/Mail
  8. # (yokmp@users.sf.net).
  9. # Feel free to change the functionnames to whatever.
  10. #
  11. # Have fun.
  12. #
  13. # p.s. excuse my bad english ...
  14. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  15.  
  16.     # text formations
  17.   fat='\e[1m'
  18.   nf='\e[0m'
  19.  
  20. # u/mount:
  21.     # the names under which the devices will be mounted
  22.     # it also sets the loops break
  23.     # so 5 devices mean 'loop five times' ... er, you got it
  24.   DEVICE_NAME=(some names here)
  25.  
  26.     # the filesystems
  27.   FS_TYPE=(btrfs ext4 ext3)
  28.  
  29.     # path of the devices
  30.   DEVICE=(/dev/sda /dev/sdb /dev/sdc)
  31.  
  32.     # path where they will be mounted
  33.     # unset for root path (may a bad idea)
  34.   DEVICE_PATH=(/var/ftp/miranda /home/yokmp/Share /home/yokmp/Backup)
  35.  
  36. # here comes the magical mount thingy
  37. function mftp()
  38. {
  39.   echo -e "\n\t${fat}Mounting:${nf}"
  40.  
  41.   for (( i=0 ; i<=${#DEVICE_NAME[@]} ; i++ )); do
  42.  
  43.     [ $i -eq ${#DEVICE_NAME[@]} ] && break
  44.    
  45.     echo -e "\n\tMount ${fat}${DEVICE_PATH[$i]}/${DEVICE_NAME[$i]}/ ${nf} ..."
  46.     echo -e "\t${fat}${DEVICE[$i]} - (${FS_TYPE[$i]})${nf}"
  47.  
  48.     mount -t ${FS_TYPE[$i]} ${DEVICE[$i]} ${DEVICE_PATH[$i]}/${DEVICE_NAME[$i]}
  49.    
  50.     [ $? -ne 0 ] && fuser -vu ${DEVICE_PATH[$i]}/${DEVICE_NAME[$i]}
  51.  
  52.   done
  53.  
  54.   echo -e "\n\t${fat}Done!${nf}\n"
  55. }
  56.  
  57. # the same as above but in 'reverse mode' ^^
  58. function uftp()
  59. {
  60.   echo -e "\n\t${fat}Unmounting:${nf}"
  61.  
  62.   for (( i=0 ; i<=${#DEVICE_NAME[@]} ; i++ )); do
  63.  
  64.     [ $i -eq ${#DEVICE_NAME[@]} ] && break
  65.    
  66.     echo -e "\n\tUnmount ${fat}${DEVICE_PATH[$i]}/${DEVICE_NAME[$i]}/ ${nf} ..."
  67.     echo -e "\t${fat}${DEVICE[$i]} - (${FS_TYPE[$i]})${nf}"
  68.    
  69.     umount ${DEVICE_PATH[$i]}/${DEVICE_NAME[$i]}
  70.    
  71.     [ $? -ne 0 ] && fuser -vu ${DEVICE_PATH[$i]}/${DEVICE_NAME[$i]} && break
  72.    
  73.   done
  74.  
  75.   echo -e "\n\t${fat}Done!${nf}\n"
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement