You are not logged in.

#1 2012-09-01 02:31:31

AaronBP
Member
Registered: 2012-08-06
Posts: 140
Website

[SOLVED] Get password for sudo

Is there a good safe way to get a password at the beginning of a script so that sudo can be used some time later (Don't want to run all of the commands as root).

Last edited by AaronBP (2012-09-01 16:14:38)

Offline

#2 2012-09-01 03:45:23

Nisstyre56
Member
From: Canada
Registered: 2010-03-25
Posts: 82

Re: [SOLVED] Get password for sudo

Why not just prompt the user to type in their password as needed?


In Zen they say: If something is boring after two minutes, try it for four. If still boring, try it for eight, sixteen, thirty-two, and so on. Eventually one discovers that it's not boring at all but very interesting.
~ John Cage

Offline

#3 2012-09-01 04:03:54

Trilby
Forum Moderator
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 14,000
Website

Re: [SOLVED] Get password for sudo

One kludge I've used is to have a "sudo echo -n" line at the beginning of a script.

This command does nothing except prompt for the password.  Then any other command in the script that is prepended by sudo will run without prompting again so long as it is before the timeout, but not all commands run as sudo.

This was handy when my script output some formated text, ran a command that needed sudo, then ouput for formatted text based on the result of the command.  It was pretty horribly ugly to have a password prompt come up in the middle of the formatted text.

I believe I've seen more "propper" ways of doing this, but 'sudo echo -n' works for me.

edit: switched to "sudo -v" thanks.

Last edited by Trilby (2012-09-01 18:10:56)


InterrobangSlider
• How's my coding? See this page.
• How's my moderating? Feel free to email any concerns, complaints, or objections.

Offline

#4 2012-09-01 04:45:27

Stebalien
Member
Registered: 2010-04-27
Posts: 1,225
Website

Re: [SOLVED] Get password for sudo

"sudo -v" is the "proper" way to do this.


Steven [ web : git ]
GPG:  327B 20CE 21EA 68CF A7748675 7C92 3221 5899 410C
Do not email: honeypot@stebalien.com

Offline

#5 2012-09-01 16:15:39

AaronBP
Member
Registered: 2012-08-06
Posts: 140
Website

Re: [SOLVED] Get password for sudo

Ah, thanks guys.

Offline

Board footer

Powered by FluxBB