Run linux command elevated
#1
I'm trying to create my first python script that runs the command mount -a on my ubuntu xbmc installation. The code that a am using is:
Code:
import xbmc,xbmcgui
import subprocess,os
os.system("mount -a")

It runs the script without a error. But as xbmc runs as a user, i'm guessing it's not allowed to run the mount command.

So i hope someone can help me with these questions.

1. How do you run a command with elevated rights? Like sudo..?
2. Is it possible to log/write the response of a os.system() command to for example syslog?

thx!
Reply
#2
Check the python script aptitude for ways to run elevated.

Although if its mount -a why not just put it in rc.local?

Cheers,
Tobias
If you have problems please read this before posting

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.

Image

"Well Im gonna download the code and look at it a bit but I'm certainly not a really good C/C++ programer but I'd help as much as I can, I mostly write in C#."
Reply
#3
I am also interested in this..seem to be a few diff solutions. Too early to say wich will work in xbmc. I will test as soon as I have figured a few things out.

Code:
import os
os.popen("sudo -S somecommand", 'w').write("mypassword")

Code:
import os

mypass = 'some password'
sudo_command = 'gedit'
p = os.system('echo %s|sudo -S %s' % (mypass, sudo_command))


Code:
os.system("xterm -c \"sudo /home/mycommand\"")
Reply
#4
Setup "passwordless" commands for sudo.

http://blog.crowdway.com/2008/01/27/passwordless-sudo/
Reply
#5
Quote:Setup "passwordless" commands for sudo.
Yes, I know. The trick is to do that without sudo Wink
Reply
#6
vikjon0 Wrote:Yes, I know. The trick is to do that without sudo Wink

Is your problem with quoting the command to sudo then? Are you even having a problem yet? Maybe I jumped the gun in answering you Smile
Reply
#7
No, the issue is to do it without modifying the OS. I.e. from an add-on. You download the add-on on a vanilla installation and it must have/gain enough permission without any preparation from the end-user. It must work with the default or perhaps xbmclive policy/sudoer setup.

I assume the only way is to ask for the admin password.

EDIT, the audio mixer do it I assume but it must have enough permission from the xbmc-live setup?
Reply
#8
vikjon0 Wrote:
Code:
import os

mypass = 'some password'
sudo_command = 'gedit'
p = os.system('echo %s|sudo -S %s' % (mypass, sudo_command))
this is proven to work, our Bootable Disk Wizard addon is using that technique - check sources on addon git.
Reply
#9
Quote:this is proven to work, our Bootable Disk Wizard
yes, I see it. Now I just have to figure out the GUI stuff then I will try it.
Reply
#10
Why not just add "users" to the filesystem options in /etc/fstab? That way xbmc can mount it without sudo.
Reply
#11
Quote:Why not just add "users" to the filesystem options in /etc/fstab?

We are talking about how to generally deal with this in python and it has been answered. I am using it now and it is working fine.
Reply

Logout Mark Read Team Forum Stats Members Help
Run linux command elevated0