I am trying to test if a user has the required sudo rights to run a command as another user without providing a password. What I have is this
sudo -u other-user -n true if [ $? -ne 0 ]; then echo "ERROR: You don't have the neccessary sudo rights" else echo "OK. You do have the neccessary sudo rights" fi
However, the scripts prints this error message if sudo requires a password
sudo: sorry, a password is required to run sudo
Is it possible to suppress this error message?
I have tried to redirect both system err and system out but the error message still appears.
sudo -u other-user -n true > /dev/null 2>&1