You are not logged in.
The topic pretty much explains it. I need this becuase the first part of my script can not be root for security reasons, but the second part which is safe needs it. And I dont want to force the user to run the script twice with different privileges.
Offline
maybe separate it on 2 scripts or similar(depending on how is the script) and then do a
subprocess.call('su -c'./script.py'')
I don't know if it would work this way, if I have to call from python to a command with some arguments I write a small shell script like
(name it scr.sh, por example)
#!/bin/Sh
su -c ./script.py
and the run it in python with
import subprocess
subprocess.call('./scr.sh')
only an idea.
-$: file /dev/zero
/dev/zero: symbolic link to '/dev/brain'
Offline
In bash it's like this:
if [ ! $( id -u ) -eq 0 ]
then echo "The program needs root priviliges!"
su -c ". part_that_needs_root_previliges"
else . part_that_needs_root_previliges
fi
first it checks if current user is root, if not it asks for password...
I thought su -c "command" needs to be quoted, and that that's why it's easier to run a separate script but I'm not sure
Offline
Sweet, you both gave ideas and it turned out pretty good. I didn't even have to use 2 scripts.
Offline