Solved

Python + mount_smbfs under Mac Fails.

Posted on 2014-04-19
3
450 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Variable is a place holder or reserved memory locations to store any value. Which means whenever we create a variable, indirectly we are reserving some space in the memory. The interpreter assigns or allocates some space in the memory based on the d…
Do you come here a lot? Are you lazy like me and don't want to go through the "trouble" of having to click your Dock's Safari icon and then having to click your Experts Exchange Favorites bookmark to get here? Well then this article is for you.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
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…

738 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