Map Network Shares

BrandonX
  9 years ago
  0

Good day all!
 
Here is a another simple script on how to map network share, with a little bit of user interaction.
Break down:
sudo: superuser privs
apt-get install : uses apt-get manager to install the desired app/program in our case cifs-utils
echo: Well.... it prints whatever you want it to print on the terminal: echo "hello world!"
read: read uses the users input to set the a variable. read with the -s flag, basically doesnt print your super secret password or any text....
 
#What the script does is is:
Step 1: Installs cifs-utils, the nessecery progam to mout  a share. You can use smb but in my example we will make use of cifs.
Step 2: Uses echo and read to gather information on the share e.g echo asks the users for info and read gets the users input. The input then gets stored as a vairable.  
Step 3:  The script validates the info with the user and then the variables are set for use.
Step 4: If the user answers y (yes) a folder is made on the desktop where the share will be mounted.
Final step: The variables are used to mount the share.
normal use: mount.cifs (location of share) (Where you want to mount it) -o (credentials)
                    mount.cifs //192.168.1.2/share  /home/bill/tmp -o user=admin,pass=1234 
 
Just keep the steps in mind while reading the script and it should all be very easy to grasp.
 
#!/bin/bash
 
#NOTE:Be sure to run script using sudo
 
#Install cifs-utils
 
apt-get install cifs-utils
 
#Credentials
echo "Path to share? e.g //192.168.1.5/lol"
read share
 
echo "What would you like to name the share folder that will be made on your desktop?"
read name
 
echo "Username needed for share? e.g Administrator"
read user
 
echo "Password of share?"
read -s pass
 
#Clear required command hashes if its a domain share
#echo "Domain name?"
#read domain
 
echo "Please verify if credentials are correct"
echo "Path to share: $share"
echo "Name of share on Desktop: $name"
echo "Username of share: $user"
#echo "Domain name: $domain"
 
echo "Continue [y/n]"
 
read ans
if [ $ans = y ] ; then
 mkdir ~/Desktop/$name 2>> /dev/null
 
 mount.cifs $share ~/Desktop/$name -o user=$user,pass=$pass
 
 echo "completed!"
#For domain share : mount.cifs $share $name -o user=$user,pass=$pass,domain=$domain
 
elif [ $ans = n ] ; then
 echo "Please try again..."
 
else
 echo "Could not interpret answer"
fi
                                       
Comments
Rebel450 9 years ago

mhmmm....


MagicMint 9 years ago

That “break down” at the beginning is useless as long as you don’t explain what your script is supposed to do. You don’t even give a name to your script !


remoulder 9 years ago

This is not a tutorial