I have edited my sudoers
file to allow my non-root user to run sudo
commands without being prompted for a password. In vim
, how do I create a function that checks whether this condition is true, if not, prompt the user if they want the script to edit and save the sudoers
file to make this condition true?
If condition is true, carry-on with rest of script. If condition is not true, the script silently edits/adds the line: %sudo ALL=(ALL:ALL) NOPASSWD: ALL
in the sudoers
file, saves and then continues on with the next part of the script.
So I've started writing the function using the code:
... #lines 1-5
passChk() {
passPut="%sudo ALL=(ALL:ALL) NOPASSWD:ALL";
passRd=sudo grep -is "$passPut" --file=/etc/sudoers;
if [ $passRd == $passPut ]; then #if sudoers already contains line from $passPut,
#exit passChk and proceed to pkgFetch.
pgkFetch;
else
echo "You will be prompted for user password. Do you want to temporarily disable this?";
read answer;
fi
if [ $answer !="y" ] || [ $answer !="n" ]; then null
elif [ $answer ="y" ]; then
$passPut|tee -a > /etc/sudoers
elif [ $answer ="n" ]; then
pkgFetch;
fi;
clear;
};
passChk;
I am recieving an error on line 9 if [ $passRd = $passPut ]; then pkgFetch; [: too many arguements
. I don't get it. I'm trying to test if directory in $passRd
contains string from $passPut
. What am I doing wrong?