Pregunta

Using Java (JSch API) I am trying to execute an Unix command on a remote machine. Now, to successfully execute this command I need to use all the environment variables already set on the remote box.

I can use export <variable> command to set the variables on runtime. But as the number of such variables is quite large I am wondering if there is any better way to use the variables in runtime.

Can anyone help please or should I explain a bit more?

¿Fue útil?

Solución

You can save variables into a file:

set > /tmp/vars
echo "A=120" >> /tmp/vars

and then "import" the variables with dot in a script like this:

set -a
. /tmp/vars
mycommand

Otros consejos

The work around I found was to use

set | mycommand

Set will manually call the initialization process and it will add environment variables into the scope.

JSch calls bash with -c. This causes .bashrc not to be initialized inside of the bash scope. Set will read the .bashrc file and other config files.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top