Solved

Python + mount_smbfs under Mac Fails.

Posted on 2014-04-19
3
417 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 37

Expert Comment

by:Gerwin Jansen
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 37

Accepted Solution

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

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

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Syslogd is a utility that traps and logs messages sent by running processes. It is configured with the syslog.conf file, which consists of lines containing a pair of fields: "the selector field which specifies the types of messages and priorities to…
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…
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 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 …

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now