yokmp

Un-/Mount multible devices

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