"sudo".execute() and retain env vars

(Sion Williams) #1

I have a requirement where I need to sudo into an oracle user, retain the environment variables from the gradle wrapper, execute the task and return.

println “$System.env.ORACLE_INSTANCE/bin/frmf2xml.sh $file OVERWRITE=YES”.execute().text

the above works perfectly if run as the oracle user. However, the following does not:

println “sudo -u oracle -E $System.env.ORACLE_INSTANCE/bin/frmf2xml.sh $file OVERWRITE=YES”.execute().text

(Luke Daley) #2

How does it not work? Do you get an error message? Does it do the wrong thing?

(Sion Williams) #3

Unfortunately, the error messages are terrible, but we have proven its an environment issue by creating a wrapper around the frmf2xml.sh that also sets the environment. This works:

println “sudo -u oracle /home/frm2xmlWrapper.sh”.execute().text

(Sion Williams) #4

Interestingly this was completely unrelated to environment variables, it was indeed doing as expected. It was my permissions on files during the sudo that was causing the problem.

This can be closed.

(Luke Daley) #5

Thanks for letting me know. Cheers.