I want to run specific commands with sudo in my servlet in wildfly.
I know that I can run specific commands with the tomcat user:
tomcat ALL=(root) NOPASSWD: /home/jur/virt.sh, /home/jur/createdisk.sh
I tried with the user 'widlfly' but that doesn't work. Now I don't know what the name of the wildfly user is. My servlet can't run the commands with sudo.
In my servlet I have this:
ProcessBuilder pb = new ProcessBuilder("sudo /home/jur/createdisk.sh " + parameter);
wildfly gives the error: "Java.io.IOExeption: Cannot run program "sudo /home/jur/createdisk.sh parameter": error=2, No such file or directory"
When I do the same in the terminal with the user 'jur', it works perfectly.
Constructor of ProcessBuilder class takes multiple arguments and the first one needs to be program name and following are arguments of the program.
For example calling ProcessBuilder pb = new ProcessBuilder("ls -l")
will give same error as you mentioned, but calling ProcessBuilder pb = new ProcessBuilder("ls", "-l")
is going to be successful.
Correct syntax in your case should be
ProcessBuilder pb = new ProcessBuilder("sudo", "/home/jur/createdisk.sh", parameter);