I want to be able to quickly check whether I both have sudo access and my password is already authenticated. I'm not worried about having sudo access specifically for the operation I'm about to perform, but that would be a nice bonus.
Specifically what I'm trying to use this for is a script that I want to be runnable by a range of users. Some have sudo access. All know the root password.
When they run my script, I want it to use sudo permissions without prompting for a password if that is possible, and otherwise to fall back to asking for the root password (because they might not have sudo access).
My first non-working attempt was to fork off sudo -S true
with STDIN closed or reading from /dev/null. But that still prompts for the password and waits a couple of seconds.
I've tried several other things, including waiting 0.3sec to see whether it succeeded immediately, but everything I try ends up failing in some situation. (And not because my timeout is too short.) It's difficult to figure out what goes on, because I can't just strace like I normally would.
One thing I know doesn't work is to close STDIN or attach it to a pipe before running sudo -S true
. I was hoping that would make the password prompt immediately fail, but it still prompts and behaves strangely. I think it might want a terminal.