Created
November 20, 2021 13:52
-
-
Save julcap/462ff42dffbb65b889c83523a22ba34e to your computer and use it in GitHub Desktop.
Create local folders and mount remote cifs shares
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The standard way to add automatic mount is using /etc/fstab. The problem i found is that when remote shares are offline | |
# the computer is slow to boot because it waits for each entry in /etc/fstab to time out. | |
# Here i am automating the mounting of remote shares so i can run it after computer has finished boot via cronjob or manually. | |
# This script creates local directories if they do not exists and mounts the remote shares using cifs. | |
#!/usr/bin/env bash | |
IFS=, | |
MOUNT_ROOT=/mnt | |
REMOTE_FOLDERS="ubuntu,proxmox,TV Shows,Steam,Music,Mix,Learning,Movies,Emulators,Music Videos" | |
REMOTE_SERVER_IP=192.168.50.253 | |
SMBPASSWD=/home/$USER/.smbpasswdNas | |
createdirectories_and_mount(){ | |
for folder in $REMOTE_FOLDERS;do | |
local_path="$MOUNT_ROOT/$folder" | |
# Create local directory to mount if it doesn't exist | |
if [ ! -d "$local_path" ];then | |
sudo mkdir $local_path | |
fi | |
# Mount to local folder | |
sudo mount -t cifs //$REMOTE_SERVER_IP/$folder $local_path -o uid=$USER,gid=$USER,credentials=$SMBPASSWD,rw,iocharset=utf8,file_mode=0744,dir_mode=0755 | |
done | |
} | |
createdirectories_and_mount | |
MOUNT_ROOT=/home/$USER | |
REMOTE_FOLDERS="Transmission" | |
REMOTE_SERVER_IP=192.168.50.86 | |
SMBPASSWD=/home/$USER/.smbpasswd | |
createdirectories_and_mount |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment