I have two programs in Java that I'm calling from bash script:
java program1 arg ... arg
sudo java program2 arg ... arg
I want to run program2 as sudo without being asked for password. I'm aware of sudoers file, but I'm not sure how to configure it to run java programs as sudo without being asked for password. Any thoughts?
Best Answer
Using wildcards in the sudoers file
In the
sudoers
file, you can use wildcards (*), thus creating the possibility to run a script with arguments.An example
I tested it with a shockingly simple python script. In the
sudoers
file I had to use the absolute path topython
:/usr/bin/python
in the line of the sudoers file:Then my (python script) code was:
Then I ran in a terminal:
without asking for my password.
Similarly, you should be able to achieve what you want by adding the following line to the
sudoers
file:And run the script by:
and you will not be asked for your password.
More information
An interesting source on how to use the
sudoers
file might be this one.