I'm newbies in bash scripting and i try to write script that add entry for cifs windows share to fstab. I writed a litle script but i'm not shure if it will work fine. I haven't linux to test it Can you help me to improve it or fix it? it will run on Debian 7/8 and Ubuntu 12.04 distrib
here is my code:
#!/bin/bash
cp -p /etc/fstab /etc/fstab.back-$(date +%F)
dir_src=//fileserver/share
dir_tgt=/mount/share
fsoptions="cifs _netdev,users,rw,auto,users,credentials=/etc/.cifspasswd,iocharset=utf8,file_mode=0777,dir_mode=0777 0 0"
mkdir -p $dir_tgt
chown -R `whoami` $dir_tgt
echo -e "$dir_src \t\t $dir_tgt \t\t $fsoptions" >> /etc/fstab
printf "put your windows login: \n"
read login
echo -e "username=$login" >> /etc/.cifspasswd
printf "\n"
printf "Now put your windows password: \n"
read password
echo "password=$password" >> /etc/.cifspasswd
echo "domain=dom.local" >> /etc/.cifspasswd
mount -a >> /tmp/mount.log
if [ $? -ne 0]
then
cat /tmp/mount.log | mail -s " $hostname $username fstab return " -a "FROM:$username@mycompany.com" it@mycompany.com
else
echo " all work fine " | mail -s " fstab ok " -a "FROM:$username@mycompany.com" it@mycompany.com
fi
Thank you for your help