Bash Script GUI for CIFS/SAMBA addition to /etc/fstab

Forum rules
Before you post please read how to get help

Bash Script GUI for CIFS/SAMBA addition to /etc/fstab

Postby grimdestripador on Fri Feb 17, 2012 3:27 pm

The following script appends the correctly formatted line to connect to a windows 2003+ share.

Write the file using gedit (text editor), copy the code for and paste into file

Code: Select all
mkdir ~/bin
gedit ~/bin/
sudo chown +x ~/bin/fstabShare

Have the prerequisites
Code: Select all
sudo apt-get install dialog samba smbfs smbclient cifs -y

To run the code, use bash
Code: Select all
sudo bash ~/bin/
Code: Select all
export windowsUsername=`dialog --stdout --inputbox windowsUsername 20 30 username`;
export windowsPassword=`dialog --stdout --inputbox windowsPassword 20 30 password`;
export serverHostname=`dialog --stdout --inputbox serverHostname 20 30 windowsServerName`;
export shareName=`dialog --stdout --inputbox shareName 20 30 ShareName`;
export credentialsLocation=`dialog --stdout --inputbox "Credentials File Location" 20 30 /root/.creds`;
export mintUsername=`dialog --stdout --inputbox "Linux Mint Username" 20 30 linuxmintUserName`;
dialog --infobox "Making Credietials File" 20 30;
echo "username=$windowsUsername">$credentialsLocation;
echo "password=$windowsPassword">>$credentialsLocation;
dialog --infobox "Making the folders for share" 20 30
mkdir /home/$mintUsername/WinShares
mkdir /home/$mintUsername/WinShares/$shareName
echo --infobox "Writing to /etc/fstab" 20 30;
echo "//$serverHostname/$shareName /home/$mintUsername/WinShares/$shareName cifs credentials=/root/.creds,nobrl,uid=$mintUsername,gid=users,_netdev,iocharset=utf8,dir_mode=0777,file_mode=0666,nounix 0 0">>/etc/fstab
umount /home/$mintUsername/WinShares/*
chown -Rv $mintUsername:$mintUsername /home/$mintUsername/WinShares;
mount -a;

expected output in /etcfstab
//windowsserver/sharename/home/lmuser/WinShares/sharename cifs credentials=/root/.creds,nobrl,uid=lmuser,gid=users,_netdev,iocharset=utf8,dir_mode=0777,file_mode=0666,nounix 0 0
// /home/lmuser/WinShares/share2 cifs credentials=/root/.creds,nobrl,uid=lmuser,gid=users,_netdev,iocharset=utf8,dir_mode=0777,file_mode=0666,nounix 0 0

expected output in /root/.creds
User avatar
Level 6
Level 6
Posts: 1060
Joined: Fri Feb 16, 2007 2:26 am

Linux Mint is funded by ads and donations.

Return to Scripts & Bash

Who is online

Users browsing this forum: No registered users and 1 guest