3

Now, before you finish thinking "Dear God! why would you want to allow that?!?", I'm wondering if it's possible.

What I'm trying to solve, could be solved in other ways, but this puts it in the functional realm of other, non *nix-y admins at my work place.

What I want to achieve is: Have a shortcut / file / what-have-you be able to be double clicked (to run it), over a samba connection, and have umount /path/to/ext-drive executed.

This could fall on it's face in many areas, one of course being the aforementioned "Why?!!?!", and I've just remembered that the mount is done via root's cron, so it may not even be able to be unmounted via some other named smb user.

Practically, I'm thinking of linking to a .sh file outside of the shares in an attempt to isolate anything with execute away from samba user tinkering.

Any thoughts?

edit

I should add that the USB ext. drive is mounted via the script that does the backups. It's not mounted at drive connection. This was hopefully a way to get around the randomly occurring failures to unmount that have cropped up in the last few weeks.

I had also thought that I could put something in cron to check if the backup process has stopped executing, if the drive is still connected, and if so - unmount it.

another edit

I'm starting to realise the futility of this question. As I said in the comments below the OP here, double clicking a file on the share from my computer, won't execute something on the server.

Solution to the problem, not the question

I'm going to accept the answer from @slm, as it's the answer to the question asked. "Is it possible to run a bash command from Windows via a samba connection?" No. No you can't. (as noted in comments below this OP too)

But to solve the problem, I've done this - and will execute it via cron every hour.

#!/bin/bash

if [ ! -f "/path/to/locking/file.txt" ]
then
    if mount | grep /pathTo/backupDriveMount ; then
        # Is still Mounted
        echo "Drive Still Mounted - Attemping unmount" >> "/path2/logFile.log"
        TEST="$(mount | grep /pathTo/backupDriveMount | cut -d' ' -f1)"
        echo "Unmounting ${TEST}"
        umount ${TEST}
    fi
fi

In English,

  1. if the locking file doesn't exist, then check the mounts for the path to the backup mount point.
  2. If it's there, extract the drive/partition
  3. Unmount the extracted location.
  • Should not be possible. – Jesse_b Jun 6 '18 at 23:53
  • Why not use one of the many automount schemes? – Ignacio Vazquez-Abrams Jun 7 '18 at 0:09
  • @Jesse_b - Yeah, the more I think about it, the more holes I see in the idea. Double clicking a file on the share from my computer, won't execute something on the server. – Mark Jun 7 '18 at 1:34
  • @IgnacioVazquez-Abrams - Can you set up an automount to automatically unmount something when it's been idle for X number of minutes, or if a file is not there? (I've edited the question to provide more background) – Mark Jun 7 '18 at 1:35
  • well, there's the insane option of: 1. setup script on server to watch a directory for changes, 2. create file in directory over samba, 3. script on server sees file being created, runs umount or whatever. – muru Jun 7 '18 at 3:58
3

This is not possible. You cannot run an executable on the Linux server remotely in this manner over the Samba connection.

If you really want to achieve something like this, you can only achieve this in 1 of 2 ways that come to mind:

  1. By remotely executing the command via PuTTY/SSH, effectively logging into the Linux box, running the command, and exiting.

    $ ssh linux-server umount /path/to/ext-drive
    
  2. By setting up a executable that could be run via a web server, where they'd be triggering the umount /path/to/ext-drive command via a CGI-BIN type of set up.

NOTE: The 2nd option above can be considered "dangerous", and I'd probably discourage anyone from using it, but I've used it in the past to expose some basic commands that I wanted to execute remotely, and SSHing into the box was not an option.

A different approach

The better alternative is likely to utilize an automounter on the Linux server. With an automounter, any time someone attempts to access a directory, an action can be triggered to mount a given partition into the Linux server's directory space. After a specified amount of time of inactivity, the automounted directory can be unmounted, automatically via the automounter.

Take a look at some of these guides for further details on setting up an automounter:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.