0

When I run

C:\Windows\System32\bash.exe -c "sudo updatedb"

from a (privileged, if needed) windows command line, I get a prompt for sudo password.

Having ALL ALL=NOPASSWD: /usr/bin/updatedb.mlocate -D in /etc/sudoers does not make a difference.

I can run sudo updatedb without a password prompt from within bash itself, regardless of the line above in sudoers.

Running without sudo yields the standard and expected updatedb: can not open a temporary file for '/var/lib/mlocate/mlocate.db'

I would like to find a windows cmd line that works so I can put updatedb in a scheduled task. If sudoers need to be modified, fine.

1
  • 1
    If you need a Windows cmd line, that would be a question for Super User.
    – muru
    Dec 5 '16 at 4:03
1

If you are working on a private computer and have no security issue regarding password protection, you could use the following workaround :

C:\Windows\System32\bash.exe -c "echo 'my_password' | sudo -S updatedb"

The -S flag means sudo will read the password from stdin. The obvious issue is that you have to explicitely write your password in your command, which isn't really safe.

EDIT:

As a sidenote, I've added the following line at the end of my /etc/sudoers file :

ALL ALL=NOPASSWD: /usr/bin/apt-get*

Afterward, runing C:\Windows\System32\bash.exe -c "sudo apt-get update" from cmd.exe worked flawlessly. Did you make sure your rule wasn't overwriten ? If there is a permission conflict in your sudoers file, bash will use the last rule written. Make sure you put your ALL ALL=NOPASSWD: line at the end of the file.

1
  • The top suggestion worked, but after adding an * to the end of the line in sudoers it also works the original way I was trying. Thank you. –
    – Gaia
    Dec 5 '16 at 18:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.