I want to allow one user to run grep (through sudo), and to grep for one specific string in one specific file. I don't want to allow this user to be able to run grep on all files. The user doesn't have read access to the file, hence the requirement to use sudo. I am trying to write a nagios check which greps the log file of another service on the machine.
However it doesn't work, sudo keeps asking for a password.
My command is:
sudo grep "string I want (" /var/log/thefilename.log (yes, there is a raw
( and some spaces in the string I want to grep)
/etc/sudoers.d/user-can-grep has this content:
user ALL=(root) NOPASSWD: /bin/grep "string I want (" /var/log/thefilename.log
This sudoers file is owned by
root:root and has permissions
The server is Ubuntu trusty 14.04.3 LTS.
How can I make this work?
which greptells me it's using
/bin/grep. AFAIK in sudo file you need to specify the full path of the binary, even if you call it without the full path.