You are not logged in.

#1 2008-02-05 09:43:08

Ugge
Member
Registered: 2006-11-11
Posts: 9

perl/python: A way for the script to gain root by asking for password?

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

#2 2008-02-05 10:16:55

ornitorrincos
Forum Fellow
From: Bilbao, spain
Registered: 2006-11-20
Posts: 198

Re: perl/python: A way for the script to gain root by asking for password?

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

#3 2008-02-05 11:35:45

ibendiben
Member
Registered: 2007-10-10
Posts: 519

Re: perl/python: A way for the script to gain root by asking for password?

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

#4 2008-02-06 01:55:36

Ugge
Member
Registered: 2006-11-11
Posts: 9

Re: perl/python: A way for the script to gain root by asking for password?

Sweet, you both gave ideas and it turned out pretty good. I didn't even have to use 2 scripts.

Offline

Board footer

Powered by FluxBB