Advertisement
Guest User

Untitled

a guest
Aug 1st, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.09 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # Put Samba Host IP as Host
  4. host="192.168.1.10"
  5.  
  6. # Desktop Path with trailing slash
  7. mountpath="/Volumes/mymounts/"
  8.  
  9. # Share Username
  10. username="skata"
  11.  
  12. # Share Password
  13. password="fuck"
  14.  
  15. # Shares Names
  16. shares=("250aris" "gawos" "500gb" "Movies" "Series" "Series-1.5" "raid")
  17.  
  18. # Ping the host to see if it exists
  19. outp=`ping -c 1 $host | grep "0% packet loss"`
  20.  
  21. # Based on ping create folders and mount
  22. # or don't mount and delete folders if they exist
  23.  
  24. if [ "$outp" = "1 packets transmitted, 1 packets received, 0.0% packet loss" ]; then
  25.     echo "Found $host, mounting file systems..."
  26.    
  27.     mount=`mount`
  28.     # echo $mount
  29.     for (( i=0; i<${#shares[*]}; i++ ))
  30.     do
  31.         dir=${mountpath}${shares[$i]}
  32.         share=${shares[$i]}
  33.         # if [ ! -d "$dir1" ]; then
  34.         #   # Can't Find Directory So Create It
  35.         #   echo "Creating Mount Point: $dir1";
  36.         #   mkdir "$dir1"
  37.         # else
  38.         #   echo "Found Mount Point: $dir1"
  39.         # fi
  40.         grep=`echo $mount | grep $share`
  41.         # echo $grep
  42.         # echo ${#grep}
  43.         if [ ${#grep} -eq 0 ]; then
  44.             if [ -d "$dir" ]; then
  45.                 echo "Mounting $share..."
  46.                 mount_smbfs //"$username":"$password"@"$host"/"$share" "$dir"
  47.             fi
  48.         else
  49.             echo "$share already exists"
  50.         fi
  51.     done   
  52. else
  53.     echo "Could not find $host..."
  54.  
  55.     # dir1=${desktop}${shr1}
  56.     # if [ ! -d "$dir1" ]; then
  57.     #   # Can't Find Directory So Do Nothing
  58.     #   echo "No Unused Mount Point for $dir1"
  59.     # else
  60.     #   echo "Found Unused Mount Point: $dir1"
  61.     #   echo "Removing..."
  62.     #   rmdir "$dir1"
  63.     # fi
  64.     #
  65.     # dir2=${desktop}${shr2}
  66.     # if [ ! -d "$dir2" ]; then
  67.     #   # Can't Find Directory So Do Nothing
  68.     #   echo "No Unused Mount Point for $dir2"
  69.     # else
  70.     #   echo "Found Unused Mount Point: $dir2"
  71.     #   echo "Removing..."
  72.     #   rmdir "$dir2"
  73.     # fi
  74. fi
  75.  
  76. # NOTE: If you have other Shell Scripts, or the Teriminal.app is running
  77. #       enabling the next line will cause the entire Terminal.app to close.
  78. #   If you are sure that you can kill the Terminal process feel free to
  79. #   uncomment the following line so that the Terminal window the script brings
  80. #   up will automatically close when finished
  81.  
  82. # KillAll Terminal
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement