0

I would like to execute the following command without interaction:

sudo grep -e "test" /etc/sudoers

I have tried the following method:

tester@compute:~$ echo 'clouduser' | sudo -S grep -e "test" /etc/sudoers
[sudo] password for tester: test ALL=(ALL) NOPASSWD: ALL

The problem is that I am getting the [sudo] password for tester: in front of the response. How I can cut that part from the front of the answer?

Thanks!

Albert
  • 191
  • 1
  • 3
  • 23

2 Answers2

3

I will answer to my question - maybe someone else will need it:

(echo 'clouduser' | sudo -Si >/dev/null 2>&1); sudo grep -e test /etc/sudoers
Albert
  • 191
  • 1
  • 3
  • 23
0

Add the following line to your /etc/sudoers file in order to turn on password-less sudo. In this case, I use john as the login account. Change to your own account id.

john ALL=(ALL:ALL) ALL

Alternatively, and perhaps better is to put that line into a file called /etc/sudoers.d/john.

David Medinets
  • 5,160
  • 3
  • 29
  • 42
  • Thanks for your reply. I needed to do that operation without any manual intervention before. I have found the answer meanwhile and posted the answer how to do it. – Albert Sep 16 '20 at 07:09