I am trying to script a non-interactive install of Meteor (JS Framework) and part of the script prompts for sudo . I cant seem to get past it w/ my scripting skills.
The install is : curl https://install.meteor.com | /bin/sh
At a later point in the script it prompts for Sudo password. I want this step to fail. And then I can script my way around the resolution .
Note:: I cannot add the user to sudoers file, its running in a shared environment that doesnt allow my user elevated access.
Best Answer
This will replace any instance of the string "sudo" (sans quotes) with "sudo -n" (sans quotes):
From the sudo manpage:
It's worth pointing out, however, that this only works if you would be prompted for a password. In other words, if you've recently run sudo, and those credentials allow you to run sudo without entering a password for 15 minutes (the default) and you run this within 15 minutes, the above command will still succeed in running sudo. Or if you are never normally prompted for a password, that will also cause success.
To invalidate the session created by recently entering sudo credentials, run
sudo -k
. Again, from the manual:If that doesn't work for you (if, for example, your security policy wouldn't request a password), you can try:
If the program sudo was running failed, sudo will fail. And from the manpage for false:
...is all false does.
What this means is that, instead of running whatever command it's trying to run with sudo, it will instead run
/bin/false
, passing the name of the original program intended to be run undersudo
as the first argument.NOTE: If you actually want the entire first line containing a sudo call to fail, these solutions won't (necessarily) make that happen. The sudo call itself will fail, but if its arguments are created in a subshell, or there are previous commands on the same line, those will work as usual. So, if the original command were:
That would become:
And
ls /humans
would still run. Probably obvious, and it likely doesn't matter, but just in case, I thought I'd mention.