How can I ask for the root password, but perform the action later?

I have a python script that I would like to add the function "Disconnect when it was done."

I know that I can use gksudo (when the user clicks "shutdown when done") to ask the user about root privileges, but how can I use these privileges later (when the script is actually completed).

I was thinking about chmod u + s in the shutdown command, so I don't need a password, but I really don't want to do this.

Any ideas how I can achieve this?

Thanks in advance, Ash.

+7
python linux ubuntu
source share
3 answers

gksudo should have a timeout, I believe that since the last execution of the gksudo command.

So, I think I’ll just throw away “gksudo echo meh” or something every minute. If you reset the timer and keep you active until you reboot.

+3
source share

Instead of the chmod u+s shutdown command, access to sudo to access this command will not be available.

As for allowing shutdown at the end of the script, I assume that you could run the whole script with sudo and then reset the privileges on the initial user at the beginning of the script?

+4
source share

Increase priority, create ( fork (2) ) a separate process, which will wait (2) , and lower priority in the main process.

+1
source share

All Articles