Tuesday, 17 September 2013

Sudo a bash script in profile.d

Sudo a bash script in profile.d

Using RedHat 6, the following script is located in
/etc/profile.d/my_custom_script.sh
function checkroot {
if [ "$(whoami)" != "root" ]; then
echo "Sorry, you are not root."
return
else
echo "You've got the powah!"
fi
}
as a normal user, and as root, the checkroot command runs as expected.
However, when running sudo checkroot either as a normal user with sudo
privileges, or as root itself, the system responds with sudo: checkroot:
command not found
The command runs successfully with sudo -i checkroot, however I don't want
to have to provide this option to sudo. What needs to change to make this
happen?

No comments:

Post a Comment