Shell – Is it possible to run a bash command from Windows via a samba connection

administrationsambashellshell-script

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.

Best Answer

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:

Related Question