You are not logged in.
Pages: 1
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
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
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)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Pages: 1