Solved

Python + mount_smbfs under Mac Fails.

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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

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.
An introduction to the wonderful sport of Scam Baiting.  Learn how to help fight scammers by beating them at their own game. This great pass time helps the world, while providing an endless source of entertainment. Enjoy!
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

690 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