How to prompt (gui) and use root password on a script?

0

I would like run a script of mine that need some root privilegies on a gui way.

For example, a simple script could be:

#!/bin/sh
clementine
sudo shutdown -h 00:00

The first line opens the clementine music player (and I don't want root privilegies to open it) and the second will halt the computer on a specific time.

I would like run the script using Alt+F2 and a dialog ask the root password to me when it is needed.

How to do this?

GarouDan

Posted 2012-06-11T11:34:00.880

Reputation: 477

Wait...replacing sudo with kdesudo should work just fine. – Bobby – 2012-06-11T11:41:57.237

@Bobby, I tried Alt+F2 typed sudo with the script localization and hit Return. Clementine opened, but the shutdown no (didn't appear nothing in system monitor)=/... – GarouDan – 2012-06-11T11:46:44.873

I say it again: replacing sudo with kdesudo in the simple script you posted did not work? – Bobby – 2012-06-11T11:50:34.803

In the question How can I pass Root Password to a script I can see something that looks like what I'm needing, but I didn't know how can I use this to perform what I need.

– GarouDan – 2012-06-11T11:51:28.317

@Bobby, nice idea. Well just put kdesudo shutdown -h 00:00 instead sudo shutdown -h 00:00 doesn't work. Maybe is the command shutdown -h 00:00 isn't made by just one parameter. But is almost^^ – GarouDan – 2012-06-11T11:55:13.803

@Bobby, Yeah! Nice. Works. Change to kdesudo "shutdown -h 00:00" works. Please write this as answer that I will embrace it. – GarouDan – 2012-06-11T11:57:24.783

Answers

1

Use kdesudo <Your command>:

#!/bin/sh
clementine
kdesudo "shutdown -h 00:00"

GarouDan

Posted 2012-06-11T11:34:00.880

Reputation: 477

@Bobby, if you put a similar answer I will embrace it instead of this answer of mine. Thx. Cya. – GarouDan – 2012-06-11T12:35:36.623