Question Mount / unmount remote folder from script?

Currently reading
Question Mount / unmount remote folder from script?

14
1
NAS
DS218
Operating system
  1. Windows
I would like to be able to mount a remote folder (CIFS / SMB), perform an rsync, and dismount the folder. If not all that, at least check if the folder is mounted and mount it if not already mounted. (I've already got the rsync script running.) I have no trouble mounting the folder using the DSM GUI, but I cannot get it to work in a script.

So far I've been testing it from an SSH terminal rather than a script. (I discovered I have to have root authority, not just admin authority, to supply mount options. I got around that problem with "sudo -i", but it think it will not be a problem in a script because I can run the script under root.) But I I thought it should be fairly straightforward, but I can't get it to work.

BTW, in the following command the username and password are dummies. This is a public share so no credentials are required except to satisfy the syntax. But DSM apparently saved credentials and validates against them (even though the remote NAS doesn't care). I'm now stuck with x and y.

I enter
root@DS218_2:~# 'mount -t cifs -o username=x,password=y,ro,vers=3.0,nodfs \\OF-Pub-NAS1\Public\ /volume1/Mount_Points/OF-Pub-NAS1/Public/'
but I get the error message
-ash: mount -t cifs -o username=x,password=y,ro,vers=3.0,nodfs \\OF-Pub-NAS1\Public\ /volume1/Mount_Points/OF-Pub-NAS1/Public/: No such file or directory

I've tried with and without the trailing slash on both the remote folder and the mount point. All attempts give the same result. But when I mount through the DSM GUI and display the results I see
Mount list.JPG

It looks to me like I've entered the correct names. Anyone see what I'm doing wrong?
 

Attachments

  • Mount list.JPG
    Mount list.JPG
    22.4 KB · Views: 40
Why are you enclosing the whole command in ' '?

You can try using double quotes around each file path (src, dst), and you may have to escape some of the characters too. Escaping uses \ before the dubious character, e.g. if you don't double quote then a <space> ' ' will break a file path but '\ ' will be interpreted as a space in the file path.
 
I don't remember what different quotings I tried, but I know I tried a lot of them. I don't think I tried quoting just the paths. I'll try that. I do know that my first few attempts had the \ acting as escape characters.

I should mention that I do not know Linux (or any flavor of *NIX) at all so I'm in foreign territory here. Do the same rules syntax apply in the SSH connection as in a script?
 
You can try using double quotes around each file path (src, dst), ...
I got a bit farther based on your suggestion, although I had to use single quotes rather than double quotes.
root@DS218_2:~# mount -t cifs -o username=x,password=y,ro,vers=3.0,nodfs '\\OF-Pub-NAS1\Public' '/volume1/Mount_Points/OF-Pub-NAS1/Public/'
That resulted in a different message:
mount: wrong fs type, bad option, bad superblock on \\OF-Pub-NAS1\Public,
missing codepage or helper program, or other error
(for several filesystems (e.g. nfs, cifs) you might
need a /sbin/mount.<type> helper program)

In some cases useful info is found in syslog - try
dmesg | tail or so.
Nothing in syslog helped, but I did check and there is no /sbin/mount.cifs.

A search of the web showed a CIFS utility package for Linux, but DSM obviously already has the facility to mount a CIFS file system. Is there some DSM-specific command I should use rather than the generic "mount"?
 
Do the same rules syntax apply in the SSH connection as in a script?
Generally yes, provided the script is running the same or very similar type of shell. You can force the shell type in script by adding the first line, e.g. to use Bash add #!/bin/bash.

What you're doing isn't something I've tried, however a useful command to try when finding where a command may be located (provided $PATH has the location in it) is which <command I'm looking for>.

Doing this you'll find /bin/mount.cifs but to run it you'll have to use sudo, e.g. to get the help text sudo mount.cifs --help. But if you're running a script in a scheduled task then (if I remember right) you don't need to use sudo if you select to run the task as root, but be very careful.

Another point that can help googling is that DSM is based on Busybox so I'd prefix and search with 'Synology DSM Busybox ' then add what I'm interested in.
 
Thank you for pointing me to mount.cifs. It worked. It was a bit tricky because I forgot to run it in verbose mode soit gave no indication that it had done anything, and the mounted folder does not show in File Station's Mount list, but the mount happened.

I was not expecting that lack of visibility in File station so I may change my plans a bit. If there is a way to mount the remote folder read-only in File station, I will do it that way and use the mount command only as fall-back if the folder becomes unmounted.
 
On the source server you could define the SMB share as read-only so that it doesn't matter what File Station does regarding w/r.

I run a Raspberry Pi I with some weather station software, and Perl I wrote that creates my a second set of web pages. I then run a task every 15 mins that copies over the latest files to a folder in /web on the NAS.

The Pi SMB shares I created are read-only: defined in /etc/samba/smb.conf using read only = yes. In File Station I've had the remote folder mounted (and auto-remounted) for a few months now and not had any problems, yet.

mounted folder does not show in File Station's Mount list, but the mount happened
That's probably because this FS feature isn't aware of a folder being used as a mount point and even if it did (which it could by looking at various files/command outputs) it wouldn't know the exact parameters it should save for reconnection:
Or shouldn't know them but it could extract command info using ps.​
But then this could be construed as snooping because File Station isn't the same as DSM unix.​
And the flip side is that some users may not want FS to harvest mount commands that are done on the command line.​
 
On the source server you could define the SMB share as read-only so that it doesn't matter what File Station does regarding w/r.
That would not work in my case. The share needs to be mounted read/write on 4 Windows computers. It's only on the Synology NAS that I want it read-only. I need the Synology NAS to do a backup but not change anything.

I think my best bet is to do everything in a script: mount, rsync, unmount.
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

Similar threads

  • Question
Hibernation is a good thought, @Rusty, but I don't think this particular drive hibernates. There's no...
Replies
2
Views
365
  • Solved
I have ZERO connections showing in the remote connection list. However, I did have a failed connection...
Replies
6
Views
12,830
  • Question
I keep thinking about this, having nothing else going on being retired, and the only problem I can foresee...
Replies
12
Views
3,265
  • Question
Have had issues with DS FINDER, not doing WOL, but DS ROUTER always works... Cannot reply to after power...
Replies
7
Views
4,830
It will work yes. There are several topics on the matter. Look for @fredbert posts on the forum, he...
Replies
1
Views
1,914

Welcome to SynoForum.com!

SynoForum.com is an unofficial Synology forum for NAS owners and enthusiasts.

Registration is free, easy and fast!

Back
Top