Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IP=1.1.1.1
- PING_ATTEMPTS=3
- SMB_SHARES_PUBLIC=(PublicShare1 PublicShare2)
- SMB_SHARES_PRIVATE=(PrivateShare1 PrivateShare2)
- MOUNT_POINT_ROOT=/Volumes
- function fnGetCredentials {
- echo "Enter your username:"
- read USER
- echo "Enter your password:"
- read -s PASS
- }
- function fnPingCheck {
- echo "Ping check"
- ping -c$PING_ATTEMPTS $IP > /dev/null
- PING_EXIT_CODE=$?
- if [ $PING_EXIT_CODE -eq 0 ]
- then
- echo "Ping check status: OK"
- else
- echo "Ping check status: Failure"
- echo "Aborting"
- exit 1
- fi
- }
- function fnMount {
- echo " Mounting $MOUNT_POINT_ROOT/$1"
- if [ ! -d "$MOUNT_POINT_ROOT/$1" ]; then
- mkdir $MOUNT_POINT_ROOT/$1
- # check if username is passed
- if [ -z $2 ]
- then
- mount -t smbfs //$IP/$1 $MOUNT_POINT_ROOT/$1
- else
- mount -t smbfs //$2:$3@$IP/$1 $MOUNT_POINT_ROOT/$1
- fi
- # if error remove directory
- if [ $? -eq 0 ]
- then
- echo " > Success"
- else
- echo " > Error"
- rmdir $MOUNT_POINT_ROOT/$1
- fi
- else
- echo " > Already mounted"
- fi
- }
- if [ ${#SMB_SHARES_PRIVATE[@]} -ne 0 ]; then
- fnGetCredentials
- fi
- fnPingCheck
- echo "Mounting public shares"
- for i in "${SMB_SHARES_PUBLIC[@]}"
- do
- fnMount $i
- done
- if [ ${#SMB_SHARES_PRIVATE[@]} -ne 0 ]; then
- echo "Mounting private shares"
- for i in "${SMB_SHARES_PRIVATE[@]}"
- do
- fnMount $i $USER $PASS
- done
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement