Run windows batch file from ssh login - env vars missing

1

I am trying to run a windows batch file from a ssh login. I have successfully installed cygwin w/ OpenSSH on the server (windows 2003).

I can log in and run the file, but the file does not run properly because it relies on an environment variable. I discovered that for security reasons not all environment variables are added to the ssh shell. I added the environment variable I need (in ~/.profile), but the file still errors out.
I modified the file and had it output the environment variable that was causing issues before, and I discovered that it was still not set. So, even though I added the environment variable, and it exists in the shell, it is not available in the shell the batch file is being run in.

How would I add the environment variable to the batch file's shell?
Modifying the file permanently is not an option; it is created by another program, and I am trying to write a git hook to run the file on another machine after a "git push"

AsherMaximum

Posted 2012-06-10T16:47:34.503

Reputation: 148

Answers

3

You could write a small shell script that sets the environment variable(s) and then runs the batch file. For example:

#!/bin/bash
export VAR1="value of VAR1"
export VAR2="value of VAR2"
./script.bat

This example assumes that script.bat is in the current working directory and that you have execute permission for it.

Fran

Posted 2012-06-10T16:47:34.503

Reputation: 4 774

that's what I ended up doing. the problem is that the script is in a folder that the build process of the program recreates, so it would get overwritten. It has to be called from that directory too, as it relies on the pwd variable. I worked around the issue though by creating the file on the fly as I needed it with echo commands. – AsherMaximum – 2012-06-11T11:21:47.627

You could put the above shell script in a place where it can persist, then put a cd ... command just before the ./script.bat to change to the appropriate directory just before launching the batch file. That way the above shell script doesn't have to be overwritten or deleted. – Fran – 2012-06-11T15:38:14.210