Linux Mounting Script

Recently I have set up a VSFTPD CentOS 7 server and chrooted all the local users to their home directory. *If you know what that means $YourPoints = $YourPoints + 5*

But when ever the system was rebooted or for any other reason that I don’t fully understand yet, the mounts from the shares to the users home directory would get lost. Because the users were chrooted into their home directories, I couldn’t use symbolic or hard links. Instead I had to use the:

mount --bind

option to make the mount accessible to the chrooted users.

But since the mount kepts getting lost and I had grown tired of the users complaining that they couldn’t access the share. Plus it was taking too long manually remounting all the shares, let alone finding out which ones had become disconnected before the users started to complain. So I created a script to check and ask me if I wanted to mount the share.

Just so you know, this is my first time scripting in BASH and I only did it because of my short lived love with Linux. Below is an example of the code in my script, I basically created one of these functions for each user:

if mountpoint -q /home/user3/ftp/files/share
 echo "user3 is mounted"
 echo "user3 is not mounted"
 read -p "Do you want to mount share? (y or n):" REPLY
 if [[ $REPLY = y ]]
  mount --bind /home/shares/share/ /home/user3/ftp/files/share

This way all I have to do is run this script and it will mount all of the shares for me. Let me know if there is an easier way to do this or if im missing something obviouse. Enjoy!

Leave a Reply