Mounting shares with python

Michael Bentley rmcore at gmail.com
Fri Jan 26 14:23:14 CET 2007


On Jan 26, 2007, at 6:40 AM, Marcpp wrote:

> Hi, when i mount a share with python...
>
> os.system ("mount -t smbfs -o username=nobody ...")
>
> the problem is that I'll to be root.
> Have a comand to send a root password...?
> I've tried
>
> os.system ("su")
> os.system ("the password")
>
> but it doesn't works.

Each call to os.system() spawns a new shell, so that approach  
wouldn't work.  If you have sudo configured such that you don't need  
a password, you can use os.system ("sudo mount -t smbfs -o  
username=nobody ...").  Otherwise (if you must use a password for  
sudo -- or if you don't have sudo), you can use popen2 module <http:// 
docs.python.org/lib/module-popen2.html> to spawn a process you can  
interact with.

-michael




More information about the Python-list mailing list