I'll weigh in on this, because I've spotted a couple of things.
- Rather than use cat >/dev/null as your null process, use something much simpler. The null command, which is just a colon (":"), is ideal, but it doesn't work for sudo (it doesn't like built-in commands), so then I use [ 1 ].
- I agree with sisco311; use gksudo, as it is designed for that purpose. (BTW, I would suggest gksudo rather than gksu.) You can, of course, use zenity instead of gksudo, but I think it's safer to use gksudo because of its design.
Here is how I prompt for the user's password. Adapt it to suit your purposes.
Code:
# Prompt for the password. Replace "the process" with a meaningful message.
SUDOPASSWORD="$( gksudo --print-pass --message 'Provide permission for the process. Type your password, or press Cancel.' -- : 2>/dev/null )"
# Check for null entry or cancellation.
if [[ ${?} != 0 || -z ${SUDOPASSWORD} ]]
then
# Add a zenity message here if you want.
exit 4
fi
# Check that the password is valid.
if ! sudo -kSp '' [ 1 ] <<<"${SUDOPASSWORD}" 2>/dev/null
then
# Add a zenity message here if you want.
exit 4
fi
Now you can just use the password in your sudo command. You'll notice that I used a Here String instead of a pipe:
Code:
sudo -Sp '' -- tee "${launcher}" <<<"${SUDOPASSWORD}"
I have to say that I'm not sure what will happen with tee, as the input (stdin) will be the sudo password. What were you trying to do with tee?
Bookmarks