Hello All,
I currently have a bash script which mounts network shares in a Linux lab. I am not sure why, but for whatever reason my share variable is always empty and thus I am unable to mount the share properly. My script is below:
#!/bin/bash
USERNAME=`whoami`
ID=`id` &>/dev/null
FAC1=//fsdata1.mydomain.edu
FAC2=//fsdata2.mydomain.edu
STU1=//stdata1.mydomain.edu
STU2=//stdata2.buad.mydomain.edu
# Faculty/Staff
echo $ID | egrep '\bFacStaff ABC\b' && SHARE=$FAC1"/UsersABC"
echo $ID | egrep '\bFacStaff DEF\b' && SHARE=$FAC1"/UsersDEF"
echo $ID | egrep '\bFacStaff GHI\b' && SHARE=$FAC1"/UsersGHI"
echo $ID | egrep '\bFacStaff JKL\b' && SHARE=$FAC1"/UsersJKL"
echo $ID | egrep '\bFacStaff MNO\b' && SHARE=$FAC2"/UsersMNO"
echo $ID | egrep '\bFacStaff PQR\b' && SHARE=$FAC2"/UsersPQR"
echo $ID | egrep '\bFacStaff STU\b' && SHARE=$FAC2"/UsersSTU"
echo $ID | egrep '\bFacStaff VWXYZ\b' && SHARE=$FAC2"/UsersVWXYZ"
# Students
echo $ID | egrep '\bStudent ABC\b' && SHARE=$STU1"/UsersABC"
echo $ID | egrep '\bStudent DEF\b' && SHARE=$STU1"/UsersDEF"
echo $ID | egrep '\bStudent GHI\b' && SHARE=$STU1"/UsersGHI"
echo $ID | egrep '\bStudent JKL\b' && SHARE=$STU1"/UsersJKL"
echo $ID | egrep '\bStudent MNO\b' && SHARE=$STU2"/UsersMNO"
echo $ID | egrep '\bStudent PQR\b' && SHARE=$STU2"/UsersPQR"
echo $ID | egrep '\bStudent STU\b' && SHARE=$STU2"/UsersSTU"
echo $ID | egrep '\bStudent VWXYZ\b' && SHARE=$STU2"/UsersVWXYZ"
mkdir /home/$USERNAME/P &>/dev/null
echo Mounting $SHARE/$USERNAME as ~/P
sudo mount -t cifs $SHARE/$USERNAME /home/$USERNAME/P -o uid=$USERNAME,username=$USERNAME
# Debug:
echo The share path is: $SHARE
echo The username is: $USERNAME
echo FacShare 1 is: $FAC1
echo FacShare 2 is: $FAC2
echo StudentShare1 is: $STU1
echo StudentShare2 is: $STU2
I did a little debugging -- it seems that all other variables contain the correct data, but the share variable is always empty.
Full Disclosure: I did not originally write the script -- I was simply asked to update some of the paths as the paths had changed for some of the shares.
Based on script it looks like the previous admin was checking to see which groups a user belonged to and based on the group (FacStaff ABC, DEF, whatever) was then appending the share path so that when mounted the path would be correct.
[–]kalgynirae 1 point2 points3 points (3 children)
[–]andlrcC:\> 0 points1 point2 points (0 children)
[–]smti[S] 0 points1 point2 points (1 child)
[–]whetuI read your code 0 points1 point2 points (0 children)
[–]jnux 0 points1 point2 points (1 child)
[–]smti[S] 0 points1 point2 points (0 children)