I would like to check if the user has sudo privileges. This is an approximate example of what I am trying to do. I am trying to get this to work across the following os: centos, ubuntu, arch.
if userIsSudo; then
chsh -s $(which zsh)
fi
I would like to check if the user has sudo privileges. This is an approximate example of what I am trying to do. I am trying to get this to work across the following os: centos, ubuntu, arch.
if userIsSudo; then
chsh -s $(which zsh)
fi
3
Answers
sudo -l
will display the commands that the user can run withsudo
privileges. If there are no commands that can be run,sudo -l
will return an error code and so you could try:Try with this:
Also, IDK how secure will be searching for his membership in the
sudo
group, i.e:Or:
Usually when you run an script you want to know if end it well or you got an error or what kind of error you got if there was any.
This is a more elaborated snippet,
sudoer-script.sh
:Now you can reuse your script, pipe it or concatenate with other commands
As a function: