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"
Answer
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.
No comments:
Post a Comment