Search code examples
pythonmount

Mount multiple shares using python


So I found a code that will allow me to mount a share. But I want to mount multiple shares to the system. Each host will be mounted to its corresponding folder on the local system. I did the below but that really didn't work out to well so trying to find out how would i do that. Using the code below.

#!/usr/bin/env python

import os

USER = "sambauser"
HOSTS = ["10.1.1.x", "10.1.1.x", "10.1.1.x", "10.1.1.x", "10.1.1.x"]
SHARES = ["n", "b", "m", "k", "w"]

for entry in SHARES:
    os.popen("mount -t cifs //%s/%s /r/loads/%s -o username=%s"%(HOSTS, entry, entry, USER)
    print "Mounted %s" %(entry)

print "done"

Solution

  • Something similar to this should help get you pointed in the right direction.

    #!/usr/bin/env python
    
    import os
    
    USER = "sambauser"
    HOSTS = ["10.1.1.x", "10.1.1.x", "10.1.1.x", "10.1.1.x", "10.1.1.x"]
    SHARES = ["n", "b", "m", "k", "w"]
    
    for share in SHARES:
        for host in HOSTS:
            os.popen("mount -t cifs //%s/%s /r/loads/%s -o username=%s"%(host, share, share, USER)
            print "Mounted //%s/%s on /r/loads/%s as %s" % (host, share, share, USER)
    
    print "done"