Environment variables over non-interactive SSH connection?

Solution 1:

Check you /etc/ssh/ssh_config (on client) and look at SendEnv option. In my case, I have SendEnv LANG LC_*.

There is some interresting informtions in the man ssh_config

Solution 2:

If you have control of the ssh command call itself, you can try something like this:

ssh user@remoteserver MYVAR1="$MYVAR1" MYVAR2="$MYVAR2" command

I also use "tee" (for visual clarity) and heredoc to send remote bash scripts:

tee << '+++' | ssh user@remoteserver MYVAR1="$MYVAR1" MYVAR2="$MYVAR2" bash
  set -x
  echo "hey, your variable is $MYVAR1"
  echo "and your other variable is $MYVAR2"
+++