Skip to content

Instantly share code, notes, and snippets.

@shivasiddharth
Last active November 15, 2023 23:42
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save shivasiddharth/3a2d6ab0febe47f695f8dd7a22a1868d to your computer and use it in GitHub Desktop.
Save shivasiddharth/3a2d6ab0febe47f695f8dd7a22a1868d to your computer and use it in GitHub Desktop.
Script to mount NAS in Linux
#!/bin/bash
set -o errexit
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root (use sudo)" 1>&2
exit 1
fi
sudo apt-get install cifs-utils
echo ""
read -r -p "Enter the address of the NAS folder that you want to mount: " nasaddress
echo ""
read -r -p "Enter the local path where you want to mount the NAS folder: " localaddress
echo ""
read -r -p "Enter the path to store credentials file: " credentialaddress
echo ""
if [ ! -d $localaddress ]; then
sudo mkdir -p $localaddress
fi
if [ ! -d $credentialaddress ]; then
sudo mkdir -p $credentialaddress
fi
echo ""
read -r -p "Enter the username of the NAS: " nasusername
echo ""
read -r -p "Enter the NAS password: " naspassword
echo ""
sudo tee -a $credentialaddress/.NASCREDS <<_EOF_
username=$nasusername
password=$naspassword
_EOF_
echo ""
echo "$nasaddress $localaddress cifs credentials=$credentialaddress/.NASCREDS,uid=1000,gid=1000,vers=1.0 0 01" >> /etc/fstab
echo ""
echo ""
echo "@reboot root /bin/bash -c 'sleep 10 && /bin/mount -a'" >> /etc/crontab
echo ""
echo "All done............................."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment