Windows Shares in /etc/fstab

A project I am doing at work involves having a Debian Linux machine mount a Windows share, and then letting a script go in and pull some data out of files for processing.  A lot of this is easily handled by Perl, but the first task is to mount the share.  And this had me stumped for a second.

The syntax for mounting a share in /etc/fstab looks kind of like this (on one line):

//servername/sharename    /mount/point   username=user,password=pass,default   0 0

Now, I had something like that set up, but when I would try to mount it by typing mount /mount/point, I would get an error like this:

[mntent]: line 21 in /etc/fstab is bad
mount: can’t find /mount/point/ in /etc/fstab or /etc/mtab

Now, I couldn’t figure out what was causing this at first.  I mean, it worked fine when I just used the mount command.  But, it turned out that the problem was a space in the Windows share name (something like /servername/share name).  I had thought that using a simple \ to escape the space would work, but on a hunch I searched to see if there was a proper way to escape, specifically for /etc/fstab.  This post explained it, and now I have the following in /etc/fstab:

//servername/share\040name    /mount/point   username=user,password=pass,default 0 0

Basically I just replaced the space with \040, which is unicode for a space.  Now I can mount it with no problems.

4 thoughts on “Windows Shares in /etc/fstab”

Leave a Reply

Your email address will not be published. Required fields are marked *