Solved

Python + mount_smbfs under Mac Fails.

Posted on 2014-04-19
3
438 Views
Last Modified: 2014-05-12
I started out with this link:

http://stackoverflow.com/questions/3090724/copy-files-to-network-path-or-drive-using-python-on-osx

But I am having a problem getting it to work. This is the output:

usage: mount_smbfs [-Nh] [-d mode] [-f mode]
                   //[domain;][user[:password]@]server[/share] path
Traceback (most recent call last):
  File "./mnt-queue.py", line 22, in <module>
    with mounted(remote_dir,local_dir):
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/contextlib.py", line 16, in __enter__
  File "./mnt-queue.py", line 12, in mounted
    raise OSError("Mount operation failed")
OSError: Mount operation failed

Open in new window


This is the entirety of the script in question:
#!/usr/bin/python
from contextlib import contextmanager
import os
import shutil
import subprocess

@contextmanager
def mounted(remote_dir,local_dir):
        local_dir = os.path.abspath(local_dir)
        retcode = subprocess.call(["/sbin/mount", "-t","smbfs",remote_dir,local_dir])
        if retcode != 0:
                raise OSError("Mount operation failed")
        try:
                yield
        finally:
                retcode = subprocess.call(["/sbin/umount",local_dir])
                if retcode != 0:
                        raise OSError ("Umount Operation Failed!")

remote_dir = "\\server\process"
local_dir = "/tmp/process"
with mounted(remote_dir,local_dir):
        print "Processing: " , os.walk(local_dir).next()[1]

Open in new window

0
Comment
Question by:DrDamnit
  • 2
3 Comments
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 40010803
Is the smb mount itself working? I mean:

/sbin/mount -t smbfs \\server\process /tmp/process
0
 
LVL 32

Author Comment

by:DrDamnit
ID: 40010842
First: I get this:
unknown34159e2aaec0:tmp drdamit$ mount -t smbfs \\server\process /tmp/process
mount: realpath /private/tmp/process: No such file or directory
unknown34159e2aaec0:tmp drdamit$ 

Open in new window


OK... so the directory doesn't exist. Fine. Let's create it:

unknown34159e2aaec0:tmp drdamit$ mkdir /tmp/process
unknown34159e2aaec0:tmp drdamit$ mount -t smbfs \\server\process /tmp/process
usage: mount_smbfs [-Nh] [-d mode] [-f mode]
                   //[domain;][user[:password]@]server[/share] path
unknown34159e2aaec0:tmp drdamit$ 

Open in new window


Now... this may be an important wrinkle: the samba share is shared so guest is mapped to the owner.

Contents of /etc/samba.conf (relevant sections):
[global]
	workgroup = drdamnit.COM
	netbios name = SERVER
	server string = %h server
	map to guest = Bad User
	obey pam restrictions = Yes
	guest account = office
	pam password change = Yes
	passwd program = /usr/bin/passwd %u
	passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
	unix password sync = Yes
	log level = 1
	syslog = 0
	log file = /var/log/samba/log.%m
	max log size = 1000
	dns proxy = No
	usershare allow guests = Yes
	panic action = /usr/share/samba/panic-action %d
	idmap config * : backend = tdb

[process]
	comment = In-Process queue
	path = /home/office/www/process
	admin users = office
	read only = No
	create mask = 0777
	force create mode = 0777
	force security mode = 0777
	directory mask = 0777
	force directory mode = 0777
	force directory security mode = 0777
	guest ok = Yes

Open in new window

0
 
LVL 38

Accepted Solution

by:
Gerwin Jansen, EE MVE earned 500 total points
ID: 40011086
Hmm. I missed the \\ - mount should be:

/sbin/mount -t smbfs //server/process /tmp/process
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show the steps for installing Python on Ubuntu Operating System. I have created a virtual machine with Ubuntu Operating system 8.10 and this installing process also works with upgraded version of Ubuntu OS. For installing Py…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question