Link to home
Start Free TrialLog in
Avatar of DrDamnit
DrDamnitFlag for United States of America

asked on

Python + mount_smbfs under Mac Fails.

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

Avatar of Gerwin Jansen
Gerwin Jansen
Flag of Netherlands image

Is the smb mount itself working? I mean:

/sbin/mount -t smbfs \\server\process /tmp/process
Avatar of DrDamnit

ASKER

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

ASKER CERTIFIED SOLUTION
Avatar of Gerwin Jansen
Gerwin Jansen
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial