(Originally posted on Stack Overflow). They suggested I try here instead. Here's the original post:
See title. I want a command that lets me query sudo. Ideally, it would return success if I still have sudo and false if sudo has expired. Getting the time left might also be useful (although if I was concerned I could just do sudo -v
to revalidate.) Oh and it shouldn't have to ask for a password.
The closest thing I've found is sudo -n true
, but the -n
option is only present on my Centos 5 machine at work. -n
fails if it has to ask for a password. Is there any other way to get this functionality? Assume I don't actually have root on all the machines I work with, so I can't install new versions of sudo to my liking.
For what it's worth I'm doing this so I can get my prompt to indicate sudo status. I like knowing which terminals are actively sudo-able. I also have a prompt that changes colors when I'm root, but I don't use root very often so that's of limited use.