views:

302

answers:

3

I have a python script that I would like to add a "Shutdown when done" feature to.

I know I can use gksudo (when the user clicks on "shutdown when done") to ask the user for root privileges but how can I use those privileges at a later time (when the script is actually finished).

I have thought about chmod u+s on the shutdown command so I don't need a password but I really don't want to do that.

Any ideas how I can achieve this?

Thanks in advance, Ashy.

+2  A: 

gksudo should have a timeout, I believe it's from the time you last executed a gksudo command.

So I think I'd just throw out a "gksudo echo meh" or something every minute. Should reset the timer and keep you active until you reboot.

Bill K
+1  A: 

Escalate priority, spawn (fork (2)) a separate process that will wait (2), and drop priority in the main process.

dmckee
+3  A: 

Instead of chmod u+sing the shutdown command, allowing passwordless sudo access to that command would be better..

As for allowing shutdown at the end of the script, I suppose you could run the entire script with sudo, then drop privileges to the initial user at the start of the script?

dbr
Good thought, but careful with the syntax of the suders file.
dmckee