bashcommandnon-interactive

Execute sudo command non-interactively


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!


Solution

  • 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