You are not logged in.

#1 2012-03-24 23:03:09

broi
Member
From: Bosnia & Herzegovina
Registered: 2011-12-10
Posts: 127

[SOLVED] Require authentication before my script executes

OK I got a little bash script where I type in how many minutes my computer will poweroff.
Normally, it can be ran with regular user even the code contains command "poweroff" which requires root privilegies so, when times up, instead of poweroff, I get message: "poweroff: must be superuser" big_smile

Now, I want it to be like, when I run it (./myscript) to require authentication before the script even start like, for example Gparted requires, so if an authentication passes, my scirpt can run and have permission to do whatever it's written in it (in this case, 'poweroff').

Thanks ^_^

Last edited by broi (2012-03-24 23:38:44)

Offline

#2 2012-03-24 23:27:40

tavianator
Member
From: Waterloo, ON, Canada
Registered: 2007-08-21
Posts: 859
Website

Re: [SOLVED] Require authentication before my script executes

(From another thread)

foppe wrote:
# Check for admin rights. If user is not an admin user, exit the script
if [ $UID != 0 ]
then
   echo "You need to be root to run this script! Exiting..."
   exit
fi

This snippet checks if you've sudo-ed it (or ran as root). All subsequent commands can be coded without sudo.

Offline

#3 2012-03-24 23:36:46

broi
Member
From: Bosnia & Herzegovina
Registered: 2011-12-10
Posts: 127

Re: [SOLVED] Require authentication before my script executes

Thank you very much!
Another solution would be executing your script with pkexec [scriptname], so you get GUI authenticaion requirement.

Offline

#4 2012-03-27 07:26:29

xekarfwtos
Member
From: Piraeus, Greece
Registered: 2009-03-17
Posts: 1

Re: [SOLVED] Require authentication before my script executes

Or you can invoke D-Bus as regular user to shutdown your computer.
For more information: http://linuxtidbits.wordpress.com/2012/ … mand-line/

Offline

#5 2012-03-27 11:40:05

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: [SOLVED] Require authentication before my script executes

Or you can add poweroff, or your script name to your sudoers file to not need a password.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

Board footer

Powered by FluxBB